how to pass JavaScript value to JSP variable
I know this is not possible. But I need to do this :
<script language = "Javascript">
function findElement() {
for(i=0; i<document.forms[0].elements.length; i++){
if(document.forms[0].elements.type == 'text') {
var elName = document.forms[0].elements.name;
var elValue = document.forms[0].elements.value;
// Display element name and value
//alert(elName +' = '+ elValue)
<%
String elName = elName;
System.setProperty(%>elName<%, %>elValue<%);
%>
}
}
}
</script>
in JSP. I need to get the name and value of the textbox in the form to just change one property on the JSP System. Any help pls'>
[741 byte] By [
n00b70710a] at [2007-11-27 6:21:00]

# 1
If data on the page needs to change based on the value, you probably have to reload the page. If you just need to save the value server-side, you can use a separate page to set it:
JS:
var img = new Image();
img.src = 'setProperty.jsp?prop=' + prop '&value=' + value;
Then in setProperty.jsp drop your java code.
# 2
Thanks man, I think that would work.
I found something else already though and it works on the same page
<%
Enumeration parameters = request.getParameterNames();
String parameterValue = " ";
String parameterName = " ";
while (parameters.hasMoreElements()) {
parameterName = (String) parameters.nextElement();
parameterValue = request.getParameter(parameterName);
}
out.println("NAME =========" + parameterName);
out.println("VALUE =========" + parameterValue);
//System.setProperty(parameterName, parameterValue);
%>
Thanks again for the help