textbox value to scriptlet
20,079
You have missed double/single quotes for the value of the location variable. If you don't need to submit the form, just use a button input element.
<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;
}
Author by
joanna
Updated on July 09, 2022Comments
-
joanna almost 2 years
<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; }
Everytime i click View Comment, there's no value printed. I want to access locate in the scriptlet and print the value in the text area. I know this is not the best way to access it, but i need to access it in this way. Can anyone help me?
-
joanna over 12 yearsbtw, it works but i always get a null value in the commentarea.
-
Manjula over 12 yearsSee the source of the page using "View source" option in your browser context menu. And check what is the value printed as the value of var location = "?"; ."locate" java variable is Null, I think. (And note that I corrected the event handle of input button to "onclick".)
-
joanna over 12 yearsi want <%=rs.getString("location")%> to be the value of var location, what should i do?
-
Manjula over 12 yearsYou know that jsp is server side language and javascript is a client side language. Therefore when user request a page, server process the request and replace all those outputs of jsp variables with their actual values. Therefore what you need is to use "'rs.getString("location")" instead of "locate" inside those duble quotes of the var location value. I am sleepy. gtg. GN
-
joanna over 12 yearsso, it should be var location = "<%= rs.getString("location")%>";? please help me, this is the last thing i need in my project.
-
Manjula over 12 yearsYes :O You should have tested that and check. It is better to check the value is null before printing there though. Otherwise you will get "null" string as the value of "location" javascript variable. Is that "rs" a database result set?