<!DOCTYPE html>
<html>
<head>
<script>
function myFunction()
{
alert("Hello World!");
}
</script>
</head>
<body>
<button onclick="myFunction()">Try it</button>
</body>
</html>
function functionname()
{
some code to be executed
}
myFunction(arg1,arg2)Declare the argument, as variables, when you declare the function:
function myFunction(var1,var2)
{
some code
}
<button onclick="myFunction('Compuhelp','Chandigarh')">Try it</button>
<script>
function myFunction(Compuhelp,job)
{
alert("Welcome " + Compuhelp + ", the " + Chandigarh);
}
</script>
<!DOCTYPE html>
<html>
<body>
<p>Click one of the buttons to call a function with arguments</p>
<button onclick="myFunction('Compuhelp','Chandigarh')">Click for Compuhelp</button>
<button onclick="myFunction('Java','Script')">Click for JavaScript</button>
<script>
function myFunction(name,job)
{
alert("Welcome " + name + ", the " + job);
}
</script>
</body>
</html>
</pre>
<button onclick="myFunction('Compuhelp','Chandigarh')">Try it</button>
<script>
function myFunction(Compuhelp,job)
{
alert("Welcome " + Compuhelp + job);
}
</script>
Click one of the buttons to call a function with arguments