Home Java Pass-value-example Pass value from JSP to JavaScript

Related Tutorials


 
 

Share on Google+Share on Google+

Pass value from JSP to JavaScript

Advertisement
We can also pass the value from a JSP page to the java script as we have done in our previous example of passing values to the java script from the HTML page.

Pass value from JSP to JavaScript

     

We can also pass the value from a JSP page to the java script as we have done in our previous example of passing values to the java script from the HTML page. Since in JSP page we can embed HTML tags as well. 

In our this example of passing values from jsp page to java script we have created a function hello() which takes value from the jsp page on click of some button and then shows it through the alert().

Here is the example code of the JSP page which is passing value to the java script as follows:

PassJSP.jsp

<%page language="java" %>
 <head>
  <title>
  Pass value from JSP to JavaScript 
  </title>
  <script language="JavaScript" >
  function hello(name)
  {
  alert("Hello! "+name);
  }
  </script> 
 </head>
  Getting Message<br>
 <input type="button" onclick='hello("JSP Example");value="Click"/>

Output:

Download Source Code

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: May 22, 2009

Related Tutorials

Discuss: Pass value from JSP to JavaScript   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:2
name
April 4, 2012
subject

comment
J RAMESH
June 27, 2012
student

good
DMCA.com