Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Javascript prompt box and jsp variable

 
Jeff Dube
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Jeff Dube
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic