Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javascript passing value to JSP

 
arpit singla
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jsp displaying elements in a table. This jsp has embedded JavaScript. I want to pass value of variable from Javascript to JSP to display the updated value. Is it possible ? if this is not possible then how can i do it.
the way i am trying to do unsuccessfully :
myjsp:
<html>
<head>
// code for getting attributes

<script language="JavaScript">
function myfunction()
{
var myvar;
// code
document.chkout.textbox.value = myvar;

}
</script>
</head>
<body>

<form name="chkout">
<table>
// calling myfunction .....
<tr>
<td align="left"><b> Grand Total </b></td>
<td align="center"> <input type="text" name="textbox" value=??> </td>
</tr>
</table>
</form>
</body>
</html>
thanks a lot for your suggestions and help..
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a little confusing. JSP's are run on the Server and the resulting page (usually rendered in html) is sent to the client. JavaScript runs client side after it is rendered as html. What is your requirements? Do you want the Page to display a running total of the values that are entered in the a text form element?
If this is the case, here is one quick solution:

[This message has been edited by Carl Trusiak (edited August 08, 2001).]
 
Sandeep Jain
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
If I have undestood what your requirement is , then I think it is possible. You can call the jsp from the javascript . and pass the value to the jsp.
document.form.action="http://172.16.80.92:8000/servlets/first.jsp?name=javascriptVar1&age=javascriptVar2"
document.form.method=post;
document.form.submit();

------------------
Try and Try Till u succeed
Sandeep Jain
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic