如何在JSP页面中使用Javascript读取下拉值
我想知道如何从JSP中读取下拉列表值。下面是我的JSP代码如何在JSP页面中使用Javascript读取下拉值,javascript,jsp,Javascript,Jsp,我想知道如何从JSP中读取下拉列表值。下面是我的JSP代码 <fieldset> <s:form theme="simple" enctype="multipart/form-data" name="uploadDocument" method="POST" action="?"> <table> <tr> <td wrap>Select The Type of Letter to Upload:<
<fieldset>
<s:form theme="simple" enctype="multipart/form-data" name="uploadDocument" method="POST" action="?">
<table>
<tr>
<td wrap>Select The Type of Letter to Upload:</td><td><s:select id="letters" list="letterList" name="ListofLetters" headerKey="-1" headerValue="--Select The Letter Type--"/></td>
<tr>
<td nowrap ><s:file name="userFile" label="userFile" size="25" id="upload" /></td>
<td class="button-blue"><s:submit action="Upload" value="Attach File" onclick=" return validateFile()"/></td>
</tr>
</table>
</s:form>
</fieldset>
它返回keyvalue,如“0,1,2等”。如何获取与单个键关联的值,以便执行正确的检查。
提前感谢:)使用此选项获取当前所选选项的文本:
var sel = document.getElementById('letters');
var selText = sel.options[sel.selectedIndex].text;
使用此选项获取当前选定选项的文本:
var sel = document.getElementById('letters');
var selText = sel.options[sel.selectedIndex].text;
希望这有帮助
希望这能有所帮助。我猜“值”是指所选选项的文本?我猜“值”是指所选选项的文本?
document.getElementById('letters').value; // returns the value ie 1 / 2 / 3 etc
var dropdown=document.getElementById('letters');
dropdown.options[dropdown.selectedIndex].text; // returns the text