<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?
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;
}