Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pass java value to javascript?

 
rahulJ james
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to access a java value in js from a jsp..

<%
strReferralValue = tempValue + strReferralValue;
%>

How do I access the strReferralValue for a validation
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I access the strReferralValue for a validation


Is strReferralValue coming from the same page or from the database?
Since you want to do only the validation stuff, there should be no problem in both the above cases. If the variable is on the same page, then validation is straight forward, if its from a database, then you've already validated it before putting it there,isn't it.

Please tell some details about what you are trying to do.
 
rahulJ james
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am defining the variable in the JSP

<%tempValue = agency.getFltReferralPerecentage(); (This value comes from a different class)
strReferralValue = tempValue + strReferralValue;
%>

I wanted to use the value of strReferralValue in JS to do a validation to check whether the sum of all its values are not more than 100..

I am using struts 2 framework
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can;t really pass anything from the JSP to the JavaScript as they run on different machine at different times. But remember that with JSP, you can use Java values to create the template text that becomes the markup (HTML and JavaScript).

For example:

(assumes use of EL not scriptlets)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic