passing jsp value to div tag
I have
<%! String sGroup=null;
%>
<input type="button" value="<%=grpDescr%>" name="<%=grpcode%>" onclick='javascript:showMac("<%=grpcode%>");'>
<script>
function showMac(val)
{
//alert(val);
sGroup=val;
document.getElementById("ShowMS").style.visibility="visible";
}
</script>
<div id="ShowMS">
<Table align="center" border="0" cellpadding="0" cellspacing="1">
<TR>
<%
Here i want sGroup value to pass a function
%>
</div>
I m getting value in javascript function but can't understand how to pass it so that i can use it in div tag table
Thanks in advance
Meghna
Message was edited by:
Meghna
[833 byte] By [
Meghnaa] at [2007-11-27 3:40:14]

# 1
You're mixing up JSP (server-side) and JavaScript (client-side) code.
You're trying to assign val which is a JavaScript variable to sGroup which is a JSP variable.
To be able to print sGroup on the page, it has to be processed on the server before the response is sent to the client, as the HTML page in this case.
JSP variables will not be available on the client-side. At best, you could put their values into HTML fields or as JavaScript constants.
# 3
You're missing the point; once you've created the page in JSP and sent it to the client, your JSP code does not receive anything!
When there are events on the HTML page, the JSP code is not involved anywhere. You can handle them in JavaScript though.
Your JSP code will come into the picture once the form is submitted. Then all the fields will be available to the JSP code using request.getParameter() or something similar.
onClick() and getElementById() have nothing to do with JSP and they happen once the JSP code has finished running.
So you cannot pass data from JavaScript/HTML to JSP unless you submit the form to the JSP.