You can hard code. But you cant pass the variables value.
The only way is to submit the form. And get the data as part of HTTPRequest(request.getParameter()).
The reason is JS runs in your browser. And servlet i.e compiled JSP runs server side..
If its possible why do we need to submit the form :-)
Thanks
Re: how to pass JavaScript value to JSP variable
Jun 4, 2007 7:55 AM
(reply 5
of 8) (In reply to
#2 )
HI
I need to get the name of the text box submitting the data and I need to get the value as well. So I wanted to do the same as this guy by making a JSP variable equal to a JavaScript one. But now that I know I cant how can I get that information into the JSP??
Heres the code:
<script language = "Javascript">
function findElement() {
for(i=0; i<document.forms[0].elements.length; i++){
if(document.forms[0].elements[i].type == 'text') {
var elName = document.forms[0].elements[i].name;
var elValue = document.forms[0].elements[i].value;
// Display element name and value
//alert(elName ' = ' elValue)
<%
String elName = elName;
System.setProperty(%>elName<%, %>elValue<%);
%>
}
}
}
</script>