2011-12-07 45 views
4
<form name="myForm" method="post" onsubmit="return getComment()"> 
     <textarea id="commentarea"></textarea> 
     <input type="text" name="locate" value="<%=rs.getString("location")%>"> 
     <input type="submit" value="View Comment"> 
    </form> 


    function getComment(){ 
     <% String locate=request.getParameter("locate"); %> 
     var location = <%= locate%>; 
     document.getElementById('commentarea').value=location; 
     return false; 
    } 

每次我點擊查看註釋,都沒有打印值。 我想訪問在scriptlet中找到並在文本區域中打印值。 我知道這不是訪問它的最佳方式,但我需要以這種方式訪問​​它。 任何人都可以幫助我嗎?textbox value to scriptlet

回答

2

您錯過了位置變量值的雙/單引號。如果您不需要提交表單,只需使用按鈕輸入元素即可。

<form name="myForm" method="post"> 
     <textarea id="commentarea"></textarea> 
     <input type="text" name="locate" value="<%=rs.getString("location")%>"> 
     <input type="button" value="View Comment" onclick="getComment()"> 
    </form> 


function getComment(){ 
    <% String locate=request.getParameter("locate"); %> 
    var location = "<%= locate%>"; 
    document.getElementById('commentarea').value = location; 
} 
+0

非常感謝。 – joanna

+0

順便說一句,它的工作原理,但我總是得到一個null值在評論區。 – joanna

+0

使用瀏覽器上下文菜單中的「查看源代碼」選項查看頁面的源代碼。並檢查打印的值是什麼值作爲var location =「?」的值; 。「定位」Java變量是空的,我想。 (並注意我將輸入按鈕的事件句柄更正爲「onclick」。) –