Example program to pass value from Html to java script

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.

Example program to pass value from Html to java script

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