Newbie - how to mix Javascript and JSP code?

Z

zalek

Hello,

How can I pass a variable created by JavaScript to JSP code?

Lets say I have a JavaScript code:

if (w_var > 5) {
w_var = 6
}

<% abc.setNum(w_var); %>

This code did not work in my JSP page.

My question: how to pass a variable calculated in Javascript to a
bean?

Thanks,

Zalek
 
H

Hal Rosser

zalek said:
Hello,

How can I pass a variable created by JavaScript to JSP code?

Keep in mind that javascript code does not run until it gets to the browser,
while jsp code runs on the server.
Javascript can be output of jsp, but to pass the value of a javascript
variable, you'll probably have to to do it in a httpRequest, Then when it
gets to the server, jsp can get it - but the javascrpt code would be on the
requesting.
 
W

Wojtek

zalek wrote :
Hello,

How can I pass a variable created by JavaScript to JSP code?

Lets say I have a JavaScript code:

if (w_var > 5) {
w_var = 6
}

<% abc.setNum(w_var); %>

This code did not work in my JSP page.

My question: how to pass a variable calculated in Javascript to a
bean?

Use the JavaScript to write to a hidden field:

document.write('<input type="hidden" name="w_var" value="' + w_var +
'">');
 
Z

zalek

zalek wrote :










Use the JavaScript to write to a hidden field:

document.write('<input type="hidden" name="w_var" value="' + w_var +
'">');

Thanks to all for the explanation - I see I cannot mix Javascript and
JSP - as Hal explained JS runs on a client side, JSP runs on a server.

My solution is little different that you Wojtek proposed - my JS
script changes the form action to "jsp-page.jsp?
parm1=value1&parm2=value2", anyway - dziekuje.

Thanks,

Zalek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top