Pages

Tuesday 11 February 2014

How to get the jsp variables in Javascript


Hi,

This Example is used to read the jsp variables from javascript().

Save the file with any name.jsp

Source code:

<html>
<head>
<script type="text/javascript">
function test(){
<% int c=0,a=10,b=20;
    c=a+b;
 %>
var result="<%=c%>";
alert("total result is"+result);
}
</script>
</head>
<body>
<br/><br/><br/><center>
<table>

<tr> <td>UserName:</td>
<td><input type="text" name="uname" id="uname"/></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="pwd" id="pwd"/></td>
</tr>
<tr> <td></td> <td><input type="submit" value="submit" onclick="return test()"/></td></tr>
</table>
</center>
</body>
</html>

Note: This Methodology works only ID's.


--------------------------------------  Thank you----------------------------------

No comments:

Post a Comment