+ Reply to Thread
Results 1 to 3 of 3

Thread: JavaScript:Tutorial, Prompt

  1. #1
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101

    JavaScript:Tutorial, Prompt

    Introduction:-
    Welcome to another JavaScript tutorial of mine..This is not used so much but still its cool to know how it works! Here you will see how the prompt works

    Solution:-
    This code goes in the <head> tags:-

    Code:
    <SCRIPT language="JavaScript"> 
     var visitorname= prompt('Please enter your name, '');
     if ( (visitorname==' ') || (visitorname=="") || (visitorname==null) ) 
     { 
       visitorname="Man"; 
     } 
    </SCRIPT>
    And this in the <Body> tags:-

    Code:
    <SCRIPT language="JavaScript"> 
     document.write("<center>Hello, " + visitorname + "!<\center>");
    
    </SCRIPT>
    Explanation:-
    Code:
     if ( (visitorname==' ') || (visitorname=="") || (visitorname==null) ) 
     { 
       visitorname="Man"; 
     }
    Here we are taking a 'precaution' so if the user enters nothing as a name or enters a space or presses Cancel we will take his name as 'Man' so we will tell him 'Hello, Man' instead of nothing..

    A Preview:-




    Conclusion:-
    As Always Feedback is welcome and the full source is attached!!
    Attached Files Attached Files
    Last edited by TcM; 12-02-2006 at 10:46 AM.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20
    I'm just curious why you included all of this

    Code:
    (visitorname==' ') || (visitorname=="") || (visitorname==null)
    I know in Java and PHP all three cases mean the same thing and only have to use one, is it necessary to include all three?

  4. #3
    xtraze is offline Programming God
    Join Date
    Dec 2006
    Location
    Sri lanka
    Posts
    911
    Rep Power
    0
    I think it's because to make this work with all kinds of browsers. As some browsers ignore certain rules.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. JavaScript:Tutorial, Redirect URL
    By TcM in forum JavaScript Tutorials
    Replies: 5
    Last Post: 01-17-2011, 04:49 AM
  2. JavaScript:Tutorial, Confirmation Box
    By TcM in forum JavaScript Tutorials
    Replies: 5
    Last Post: 11-07-2009, 08:13 PM
  3. JavaScript:Tutorial, Using Arrays
    By TcM in forum JavaScript Tutorials
    Replies: 25
    Last Post: 07-27-2009, 04:13 AM
  4. JavaScript:Tutorial, Your First Game!
    By TcM in forum JavaScript Tutorials
    Replies: 35
    Last Post: 06-11-2009, 01:27 PM
  5. JavaScript:Tutorial, Loops
    By TcM in forum JavaScript Tutorials
    Replies: 4
    Last Post: 12-13-2006, 06:53 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts