Home Java Pass-value-example Example program to pass value from Html to java script
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Example program to pass value from Html to java script

Advertisement
We can also pass the values from html code to java script easily.

Example program to pass value from Html to java script

     

We can also pass the values from html code to java script easily. To show this we have created an example Html page which will pass the value to the java script function and this value will be shown with the java script's alert() method.

In this example we have made a java script function hello() which will display the name which has been passed from the HTML page. We have created a button and it calls the hello() function defined in java script with the argument. When we pass the argument to this method hello() in our example html page it pass it to the java script of the page and there we can display or use it.

Here is the full example code of PassHTML.html page as follows:

PassHTML.html

<HTML>
<HEAD>
<TITLE> Pass value from HTML to JavaScript </TITLE>
<script language="JavaScript" >
function hello(name)
{
   alert("Hello! "+name);
}
</script> 
</HEAD>
<BODY>
Get Hello Message<br>
<input type="button" onclick='hello("Rose India");' value="Click"/>
</BODY>
</HTML>

Output of the above example is as follows:

Download Source Code

Advertisements

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 23, 2009

Ask Questions?    Discuss: Example program to pass value from Html to java script  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com