JavaScript
  Home arrow JavaScript arrow Page 4 - 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  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
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 / 13
    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 - Prompting the Prompt Box


    (Page 4 of 4 )

    Next we are going to create a program to insult people using a Prompt Box. The prompt box asks for a value. If the user inputs one and clicks OK, it will return the value to our program; if they click CANCEL, it will return a null value.


    <html>

    <head>

    <script type="text/javascript">

    function disp_prompt()

    {

    var name=prompt("Enter Your Name for a Prediction","Some Loser")

    if (name!=null && name!="")

    {

    document.write("Hello " + name + "! I predict you will not have a date this weekend!")

    }

    }

    </script>

    </head>

    <body>


    <input type="button" onclick="disp_prompt()" value="Click for a Friendly Greeting" />


    </body>

    </html>

    Again, we have decided to allow the user to push a button to trigger our pop-up. Remember how we were lured into a false sense of security with those Jack in the Boxes? Well this is the digital version. We even give the text box a nice caption so people think everything will be okay: Click for a Friendly Greeting

    When the user clicks the button it asks the user to Enter a Name for A Prediction. It displayed a default value of Some Loser (this is where things begin to go downhill for the user muahahah). Whatever they type into the prompt (and then press OK) it will then say:

      Hello James! I predict you will not have a date this weekend!

    Where James is the value they typed in.

    If they clicked the CANCEL button, nothing would have occurred.


    If we wanted to do the above without using a button for the user to press (ie; we prompted the user when the page loaded) we could do so this way:


    <html>

    <head>

    <script type="text/javascript">


    {

    var name=prompt("Enter Your Name for a Prediction","Some Loser")

    if (name!=null && name!="")

    {

    document.write("Hello " + name + "! I predict you will not have a date this weekend!")

    }

    }

    </script>

    </head>

    <body>

    </body>

    </html>

    The same result without the user having to click the button.

    Well, that's it for this episode. Have fun scaring small children with your pop-up boxes; I know I will.

    And be sure to come back for the next tutorial, where we discuss Functions.

    Till then...


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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

    JAVASCRIPT ARTICLES

    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in
    - Active Client Pages at the Server
    - ACP Tab Web Page
    - Finishing a Slide Show Application with jQue...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT