• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is it possible to embed jsp tags in javascript??  RSS feed

 
Bill Brasskey
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to embed jsp tags in javascript??
I want to have only one html form, yet submit data to different pages for processing. Submit buttons call corresponding jscript method with onClick event...Problem is, I want to append form data to the url, and it's static in the below functions.
I want to do something like this....

<script language = "JavaScript">
function onEdit()
{
document.form1.action = "edit.jsp" //but I want to append data..something like "edit.jsp?id=<%=id%>"
}
function onReport()
{
document.form1.action = "report.jsp"
}
</script>
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37181
515
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bill,
If "id" is known when the jsp is writing out the HTML code you can do that. If it is part of what the user selected on the form, you can't. But since you are using the action and submit semantics, all the form parameters gets passed regardless of what action you submit to.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It all depends on what you want to do.
If you want to create Javascript on the server before sending it to the client, that's the way to do it.
If you expect the JSP code to be executed during a call to the Javascript function, you're thinking wrong.
 
Santosh Maskar
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
You can set the mode for every opration like when user select the Report the set one hidden property and assing the value report to it , if user select the edit the change its value to edit , in java script you can check the value of that hidden prpoerty and call the appropreate action for this

eg. if user press edit the
document.form.mode.value ='edit
when user click on Report then
document.form.mode.value ='edit

In java Script
Function OnSubmit(Mode)
{
if mode == 'EDIT'
form.action = edit.jsp
else
if mode = 'REPORT'
from.action = report

.....
and so on you can do this


Regards
Santosh
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!