• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP, JavaBean Coding with JavaScript

 
peanut
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way whereby the values of JSP variables be assigned to the JavaScript variables and vice versa?
 
Mani Balasubramanian
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried this
Jsp variable in javascript:
<script language="javascript">
var javascriptVar = "<%=jspVar%>";
</script>
The otherway round is not possibile directly. Either you have to pass the javascript variable as a url to another jsp page or submit the page to another jsp page with javascript variable as a hidden field.
 
peanut
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have tried the example u gave me but it will give me syntax error when i run it.
 
Angela Poynton
Ranch Hand
Posts: 3143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you tried it did you assign a value to jspVar??

You might want to print out javascriptVar in the Javascript too!!
 
peanut
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i did assign the values to the JSP variable n assign to JavaScript variable but it will give me error - syntax error.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"peanut",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp .
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please re-register with a new name which meets the requirements.
Thanks.
Dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic