
As we know javascript is basically a function that perform its task, we call this function on button with firing a click event named "onclick( )". We give function name into empty parantheses and apply it on button.
When user press button this function is called and javascript runs.
Here is the given code.........
Code:
<html>
<head>
</head>
<body>
<p>Press button to see alert box</p>
<input type="button" onclick="myfunction()" value="Google">
<script type="text/javascript">
function myfunction()
{
var r;
r=confirm("Do you really want to go to this address ?")
if (r==true)
{
window.location = "http://www.google.com/";
}
else
{
alert("Thanx for not leaving us")
}
}
</script>
</body>
</html>
</head>
<body>
<p>Press button to see alert box</p>
<input type="button" onclick="myfunction()" value="Google">
<script type="text/javascript">
function myfunction()
{
var r;
r=confirm("Do you really want to go to this address ?")
if (r==true)
{
window.location = "http://www.google.com/";
}
else
{
alert("Thanx for not leaving us")
}
}
</script>
</body>
</html>
Please give your feedback, it will help us to enhance the quality of our matter.
Comments
Post a Comment
your Comment is sent for moderation, Thankyou