Home arrow JavaScript arrow Page 3 - Javascript Pop-up Boxes
JAVASCRIPT

Javascript Pop-up Boxes


In our last article I filled your puny brain with the knowledge of JavaScript operators. In this article we are going to learn about pop-up boxes. That's right, those sometimes annoying, sometimes helpful things that leap out at the user and ask them to do stuff will be covered here.

Author Info:
By: James Payne
Rating: 4 stars4 stars4 stars4 stars4 stars / 16
November 07, 2007
TABLE OF CONTENTS:
  1. · Javascript Pop-up Boxes
  2. · Pop-up Boxes
  3. · Confirm Box
  4. · Prompting the Prompt Box

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Javascript Pop-up Boxes - Confirm Box
(Page 3 of 4 )

If you want to give a user an option, you can use the Confirm Box. The user will have the choice of saying OK or Cancel. Here it is in code:


<html>

<head>

<script type="text/javascript">

function disp_confirm()

{

var r=confirm("Choose Wisely")

if (r==true)

{

document.write("Oh No! Now you did it!")

}

else

{

document.write("You canceled your paycheck!")

}

}

</script>

</head>

<body>


<input type="button" onclick="disp_confirm()" value="Click Me Fool" />


</body>

</html>

You will notice a few new things in the above example. Don't fret about those too much for now. First, we added a Function, which we will hopefully learn to do later in this tutorial. We also added a button to the page as well, that says: Click Me Fool.

This particular Confirm Button doesn't trigger when the page loads, although it could. Instead, we use our Click Me Fool button to have the user trigger it. When they click it the following pop-up appears:




If the user clicks OK, it will print the following to the screen:

  Oh NO! Now you did it!

If the user clicks the CANCEL button, the following prints to the page:

  You canceled your paycheck!

The confirm button relies on a boolean value stored in a variable called r. If the user clicks on the OK (or true), it does one thing, if they choose CANCEL (or false) it does another.

You can also do this with a page load instead of having the user click on a button:


<html>

<head>

<script type="text/javascript">


{

var r=confirm("Choose Wisely")

if (r==true)

{

document.write("Oh No! Now you did it!")

}

else

{

document.write("You canceled your paycheck!")

}

}

</script>

</head>

<body>

</body>

</html>


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials