簡體   English   中英

將值從下拉列表和文本框傳遞到JSP中的JavaScript

[英]passing values from drop down list and text box to JavaScript in JSP

在此處輸入圖片說明 我試圖將兩個值傳遞給我從下拉列表中獲取的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”。 同樣,當我將它們放在一起時,第一個拒絕工作。 我在這里做錯了什么? 請幫助?

您正在調用getElementByID但是<input type="text" name="extNum" />沒有ID。

您沒有在文本字段中使用id,但是您正在使用getElementById ..

而是使用getElementByTagName來

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM