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



Pass value from JSP to JavaScript
Posted on: May 22, 2009 at 12:00 AM
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

Related Tags for Pass value from JSP to JavaScript:
htmlcjsptagspageembedtagjsecanceinmlasmcajemagesspinchtmllss


More Tutorials from this section

Ask Questions?    Discuss: Pass value from JSP to JavaScript   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.