Example program to pass value from Html to java script

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

Ads

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

Ads
Share on Google+Share on Google+

Example program to pass value from Html to java script

Posted on: May 23, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Example program to pass value from Html to java script  

Post your Comment


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

Ads

 

Ads