【发布时间】:2014-01-22 16:56:35
【问题描述】:
您好,我是 JSP 的新手,正在尝试将标题中的选定值显示为动态文本。但是每次我选择它都会显示选项值而不是文本。以下是我尝试过的。
HTML 下拉菜单
<select id="country" name="country_code">
<option value="1">Puerto Rico</option>
<option value="63">Philippines</option>
<option value="others">Others</option>
</select>
JSP 标记
<%
String countrycd = request.getParameter("country_code");
String countryTxt = request.getParameter("country_code");
%>
这是我的脚本
<script>
document.getElementById("country").value = '<% out.print(countrycd); %>';
var e= document.getElementById("country");
var str = e.options[e.selectedIndex].text;
alert(str);
</script>
这是我的 html 代码,我需要在其中显示所选文本而不是值,例如,如果用户选择菲律宾,它应该显示为菲律宾而不是代码 63
<h2>By Country: <% out.print(countrycd);</h2>
任何帮助都会非常感激!
谢谢。
编辑:
电流输出
在标题中从下拉列表中选择菲律宾:按国家/地区: 63
预期输出:
如果选择了菲律宾,则应从下拉列表中显示
按国家/地区:菲律宾不是 63。
【问题讨论】:
标签: java javascript html jsp web