File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Pass java value to javascript? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Pass java value to javascript?" Watch "Pass java value to javascript?" New topic
Author

Pass java value to javascript?

rahulJ james
Ranch Hand

Joined: Oct 03, 2008
Posts: 123
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

Joined: Jun 06, 2007
Posts: 2716
    
    6

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.


SCJP, SCWCD.
|Asking Good Questions|
rahulJ james
Ranch Hand

Joined: Oct 03, 2008
Posts: 123
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

Joined: Jan 10, 2002
Posts: 61610
    
  67

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)


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pass java value to javascript?