+ Reply to Thread
Results 1 to 3 of 3

Thread: JavaScript:Tutorial, Prompt

  1. #1
    TcM
    TcM is offline
    Code Warrior TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM's Avatar
    Join Date
    Aug 2006
    Posts
    11,461
    Blog Entries
    6

    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
    Last edited by TcM; 12-02-2006 at 12:46 PM.

  2. #2
    Co-Administrator John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John's Avatar
    Join Date
    Jul 2006
    Age
    21
    Posts
    5,885
    Blog Entries
    25
    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?

  3. #3
    Programming God xtraze is an unknown quantity at this point
    Join Date
    Dec 2006
    Location
    Sri lanka
    Posts
    908
    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, Display MsgBox
    By TcM in forum Javascript
    Replies: 16
    Last Post: 08-13-2009, 07:29 AM
  2. JavaScript:Tutorial, Your First Game!
    By TcM in forum Javascript
    Replies: 35
    Last Post: 06-11-2009, 03:27 PM
  3. JavaScript:Tutorial, Digital Clock
    By TcM in forum Javascript
    Replies: 11
    Last Post: 06-05-2009, 01:30 AM
  4. JavaScript:Tutorial, Loops
    By TcM in forum Javascript
    Replies: 4
    Last Post: 12-13-2006, 08:53 AM
  5. JavaScript:Tutorial, Break Out Of Loops
    By TcM in forum Javascript
    Replies: 0
    Last Post: 12-08-2006, 05:35 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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