my dog learned polymorphism*
The moose likes Servlets and the fly likes javascript passing value to JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "javascript passing value to JSP" Watch "javascript passing value to JSP" New topic
Author

javascript passing value to JSP

arpit singla
Ranch Hand

Joined: Jun 18, 2001
Posts: 66
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

Joined: Jun 13, 2000
Posts: 3340
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).]


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Sandeep Jain
Ranch Hand

Joined: Oct 25, 2000
Posts: 124
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


Try and Try Till u succeed<br /> <br />Sandeep Jain
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javascript passing value to JSP
 
Similar Threads
save checked value in checkbox to database
How to keep the selected value ?
Internationalization login thru to...
using Multiple submit buttons.
have problem with multiple forms on a jsp