File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Javascript prompt box and jsp variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Javascript prompt box and jsp variable" Watch "Javascript prompt box and jsp variable" New topic

Javascript prompt box and jsp variable

Jeff Dube
Ranch Hand

Joined: Jun 14, 2001
Posts: 44
Hi all,
How can i take the users entry from a prompt (javascript) dialog box and assign it to a jsp to pass it to a bean.
The reason is simple. I have a list of values that offers the possibility to add an extra option so i need to take the value and pass it
Shama Khan
Ranch Hand

Joined: Aug 14, 2000
Posts: 185
JSP Page would contain the javascript that would present the dialogue box to the user and then get the value from the dialogue box and assign it to some variable. Then within the javascript, you can have the code <%=setBoxData(yourVariable)%> where setBoxData would be method from the bean. Of course, I mean simple beans.
I hope that provides a bit of direction.

[This message has been edited by Shama Khan (edited July 12, 2001).]

Jeff Dube
Ranch Hand

Joined: Jun 14, 2001
Posts: 44
Thanks but there is a problem when i am trying it.
Here is part of my code with the generated error
What am i doing wrong?
<SCRIPT LANGUAGE="javascript">
function validateFields(objForm) //Receiving the form object
if (document.frmWork.lstWork.value == "Other")
newWorkType = prompt('Please, type your new work category.');
insertList is the name of my bean (simple bean)
And here is my error:
Error: Syntak error
Thank you
karl koch
Ranch Hand

Joined: May 25, 2001
Posts: 388
you cant assign values from JavaScript to JSP directly.
JSP are running on server side and the thing displayed in your browser is pure HTML (and probably Javascript).
JavaScript is downloaded with the page and running on your computer in the browser's JavaScript engine.
what you need to do is to get the values from your prompt and addadd it as parameters to the URL of your JSP.
then call the this URL and in the JSP you can read the value with the getParameter(..) method.
as an alternative you can also set the value from javascript to a hidden field in a form (where the action is set to your jsp) and then submit the form (probably even easier).
hope this helps. di it ?
I agree. Here's the link:
subject: Javascript prompt box and jsp variable
It's not a secret anymore!