This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Javascript prompt box and jsp variable" Watch "Javascript prompt box and jsp variable" New topic
Author

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
Thanks
Jeff
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.
Shama


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


Shama
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?
Code:
<SCRIPT LANGUAGE="javascript">
function validateFields(objForm) //Receiving the form object
{
...
if (document.frmWork.lstWork.value == "Other")
{
newWorkType = prompt('Please, type your new work category.');
<%=inserList.setNewOption(newWorkType);%>
......
</script>
insertList is the name of my bean (simple bean)
And here is my error:
Error: Syntak error
Thank you
Jeff
karl koch
Ranch Hand

Joined: May 25, 2001
Posts: 388
hi,
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 ?
karl
 
Don't get me started about those stupid light bulbs.
 
subject: Javascript prompt box and jsp variable
 
Similar Threads
How to fetch value from Text box of JSP page
parameter from jsp to javascript function?
using JSP inside javascript
passing a jsp variable as an argument to he javascript
Is it possible to pass a value from JSP to Javascript