participate


Embedded Server - how to pass JavaScript value to JSP variable
<<   Back to Forum  |   Give us Feedback
This topic has 8 replies on 1 page.
shyagale
Posts:1
Registered: 3/31/05
how to pass JavaScript value to JSP variable   
Mar 31, 2005 11:04 PM

 
<Script language="JavaScript">
function test( x )
{
<%
int num = x;
num = num * 2;
%>

v.value = "<%out.print(num);%>";
}
<input type="button" name="b" value="test" onClick="test(5)">
<input type="text" name="v" value="0">


In short, I am trying to pass JavaScript value to JSP variable. I hope that it is possible to

do that. If it is possible then how can I do it. I want to assing the variable x passed to the

JavaScript function called test to the JSP variable called num.
 
elangovijay
Posts:4
Registered: 6/2/05
Re: how to pass JavaScript value to JSP variable   
Jun 2, 2005 9:58 PM (reply 1 of 8)  (In reply to original post )

 
Hai,
i dont think so, that is not possible, u can pass jsp variable to javascript,through hidden fields vice versa is not possible
 
Ram_Jack
Posts:1
Registered: 6/5/06
Re: how to pass JavaScript value to JSP variable   
Jun 5, 2006 2:41 AM (reply 2 of 8)  (In reply to original post )

 
You can hard code. But you cant pass the variables value.
The only way is to submit the form. And get the data as part of HTTPRequest(request.getParameter()).

The reason is JS runs in your browser. And servlet i.e compiled JSP runs server side..

If its possible why do we need to submit the form :-)
Thanks
 
soumen_mallick
Posts:1
Registered: 6/14/06
Re: how to pass JavaScript value to JSP variable   
Jun 14, 2006 4:26 AM (reply 3 of 8)  (In reply to #2 )

 
If I have to submit the form to get the data as a HTTP request then how is the javascript function looks like?

This is urgent & needed now.
 
Amit_Ruhela
Posts:3
Registered: 11/15/05
Re: how to pass JavaScript value to JSP variable   
Apr 21, 2007 9:36 AM (reply 4 of 8)  (In reply to #3 )

 
refer to following url

http://swjscmail1.sun.com/cgi-bin/wa?A2=ind0012&L=jsp-interest&D=0&P=3090
Amit Ruhela
 
n00b70710
Posts:7
Registered: 12/19/06
Re: how to pass JavaScript value to JSP variable   
Jun 4, 2007 7:55 AM (reply 5 of 8)  (In reply to #2 )

 
HI

I need to get the name of the text box submitting the data and I need to get the value as well. So I wanted to do the same as this guy by making a JSP variable equal to a JavaScript one. But now that I know I cant how can I get that information into the JSP??

Heres the code:

<script language = "Javascript">
function findElement() {
for(i=0; i<document.forms[0].elements.length; i++){
if(document.forms[0].elements[i].type == 'text') {
var elName = document.forms[0].elements[i].name;
var elValue = document.forms[0].elements[i].value;
// Display element name and value
//alert(elName ' = ' elValue)
<%
String elName = elName;
System.setProperty(%>elName<%, %>elValue<%);
%>
}
}
}
</script>


Any help would be appreciated. Thanks
 
milis Click to block this message from display
Posts:54
Registered: 10/4/07
Subject blocked   
May 23, 2008 11:48 PM (reply 6 of 8)  (In reply to original post )





 
User/Message blocked
 
milis Click to block this message from display
Posts:54
Registered: 10/4/07
Subject blocked   
Jun 2, 2008 2:13 AM (reply 7 of 8)  (In reply to original post )





 
User/Message blocked
 
DonDavis Click to block this message from display
Posts:24
Registered: 10/12/07
Subject blocked   
Jun 13, 2008 5:19 AM (reply 8 of 8)  (In reply to original post )





 
User/Message blocked
 
This topic has 8 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 25
  • Guests : 132

About Sun forums
  • Oracle Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Oracle Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums