将值从下拉列表和文本框传递到JSP中的JavaScript

时间:2013-06-24 16:28:26

标签: java javascript jsp dwr

enter image description here我试图将两个值传递给我从下拉列表中获取的JavaScript,另一个是从文本框中指定的用户,我在JSP文件中有以下内容:

<select id="selectLine">
    <c:forEach var="line" items="${availableLines}">
        <option value="${line}">${line}</option>
    </c:forEach>
<select>
<label> Extension number to add </label>
<input type="text" name="extNum" />
<button onclick="insertDN();">Insert</button>

我还有一个java脚本,它使用DWR将值传递给名为DBOps的Java类:

<script type="text/javascript">
    function insertDN(){

     var selectedLine = document.getElementById("selectLine").value;
     var selectedExt = document.getElementById("extNum").value;
     DBOps.insertDN(selectedLine, selectedExt);

    }

“selectedLine”的第一个单独工作正常,它确实将正确的值传递给函数,但第二个不是“selectedExt”。此外,当我把它们放在一起时,第一个拒绝工作。我在这做错了什么?请帮忙吗?

2 个答案:

答案 0 :(得分:1)

您正在呼叫getElementByID,但<input type="text" name="extNum" />没有ID。

答案 1 :(得分:0)

您没有在文字字段中使用ID,但您使用的是 getElementById ..

而是使用getElementByTagName

相关问题