If you're new here, you may want to subscribe to my RSS feed. So that you can read the latest updates about Web2.0 tools, Making Money Online, Tips in SEO, Ajax and many more. Thanks for visiting ProgramimiCOM!
Confirming with JavaScript is actually quite easy. You can just use a simple if/else statement with it and then have something happen in each situation.
What we’ll be using is the function confirm(). The confirm function is set as a variable initially then you can use the associated variable to check the outcome of the confirmation. On the user end they get a small alert window with your question asked in it and either an “OK” or “Cancel” option.
So, to begin we need to define our confirm pop-up. For this example we’ll ask the user if they want a cookie.
var wants_a_cookie = confirm(“Would you like a cookie?”);
That will put up the window, however there will be no consequence whether they press OK or Cancel. That’s where the if/else comes into play. The confirm() function when acknowledged will return either TRUE or FALSE. What we can do is just have a situation for each option. For this example I’ll just have an alert pop up telling them if they or if they don’t want a cookie.
if( wants_a_cookie ){
alert(“Hooray! You want a cookie!”);
}
else{
alert(“Oh no, you don’t want a cookie!”);
}
And that’s it! If you want the entire code to copy into your file it would look like this:
<script language=“JavaScript” type=“text/javascript”>
var wants_a_cookie = confirm(“Would you like a cookie?”);
if( wants_a_cookie ){
alert(“Hooray! You want a cookie!”);
}
else{
alert(“Oh no, you don’t want a cookie!”);
}
</script>
Print This Post
Email This Post
Comments RSS
TrackBack Identifier URI
You must be logged in to post a comment.