Home
 
 
Search:  
C C++ Perl PHP Python HTML ShellScripts
 
 
  Coding Books
  Tutorials
  Search Code
  Browse Code
  Link to Us
  Site News
  Contact Metalshell
 
 
 
  Submit Code   Statistics
 



HTML & XHTML : The Definitive Guide    (ISBN: 059600026X)


 

 List Price: $34.95
 Our Price: $34.95
 Used Price: $5.50

 Release Date: August, 2000
 Manufacturer: O'Reilly & Associates (Paperback)
 Sales Rank: 1,623

 Author: Chuck Musciano, Bill Kennedy









More Info

 Javascript Confirm Prompt 2002-09-14 18:43:26
  html 
Category: source:html:javascript
Description: Example on how to use the prompt and confirm function's
Platform: all
Author: mind
Viewed: 33532
Rating: 3.4/5 (73 votes)
If you have any questions about this piece of code or still need help, try posting your question on the forum.

 

Printable Version
confirm_prompt.js
<!-- confirm_prompt.js - mind (mind@metalshell.com) -->

<!-- this example shows how to use the prompt and confirm -->
<!-- function's to ask questions and confirm the results -->

<!-- http://www.metalshell.com -->

<!-- start our javascript -->
<script language=JavaScript>
        // create our function
        function QuestIon()
        {
                // prompt("message", "message2");
                // message will be the header of the popup box
                // message2 will be written to the text area

                // create a variable storing the results of prompt
                var inPut = prompt("Enter your name", "");

                // check to see if anything was entered
                // null == pressing cancel
                // ""   == entered nothing and pressing ok
                if (inPut == null || inPut == "")
                {
                        // confirm("message..") pops up a window with
                        // 'message..' with two buttons (ok/cancel)

                        // print error message with confirmation buttons
                        // returns 1 on success 0 on failure..
                        if (confirm("Nothing Entered, Try again?"))
                        {
                                // create a variable (inPut) storing the
                                // results of prompt();
                                var inPut = prompt("Enter your name", "");

                                // check to see if anything was enetered
                                if (inPut == null || inPut == "")
                                {
                                        // print failure
                                        alert("Nothing was entered.");

                                        // exit our javascript
                                        return;
                                }

                                // print success/results
                                document.write("Hello, " + inPut);
                        }
                }

                // inPut was neither null nor ""
                else
                {
                        // print success/results
                        document.write("Hello, " + inPut);
                }
        }

        // end of our javascript
</script>

<!-- place this code anywhere on your html document (example) -->

<!-- align our link below -->
<div align=center>
        <!-- make a link that points to our js function QuestIon() -->
        <a href="javascript: QuestIon();">Click Here!</a>
</div>
Rate this code:
(Not Helpful)  (Very Helpful) 

 
 
   Developer.*  
   Blue Parrots  
   Technipal  
   Defy Magazine  
   Code Project  
   Prog. Heaven  


Got Money?