JavaScript
  Home arrow JavaScript arrow Page 3 - Javascript Pop-up Boxes
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Javascript Pop-up Boxes
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 12
    2007-11-07

    Table of Contents:
  • Javascript Pop-up Boxes
  • Pop-up Boxes
  • Confirm Box
  • Prompting the Prompt Box

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    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>

    More JavaScript Articles
    More By James Payne


       · Hi, thanks for dropping by and reading my article. In this issue we discuss the...
     

    JAVASCRIPT ARTICLES

    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget
    - Ajax Hack for Entering Information Without R...
    - EXT JS 2.1 Overview
    - Using the Style Object for Zebra Tables with...
    - Binary Searching
    - An Improved Approach to Building Zebra Tables
    - Assigning Background Colors Dynamically to Z...
    - Building Zebra Tables with CSS and JavaScript
    - JavaScript: Array Objects
    - A Closer Look at Smart Markers with Yahoo! M...
    - Using Polylines and Smart Markers with Yahoo...







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway