Lost Password?

  #1 (permalink)  
Old 12-02-2006, 09:18 AM
TcM's Avatar   
TcM TcM is offline
Terminator - I'll be back
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 5,731
Rep Power: 47
TcM is a jewel in the roughTcM is a jewel in the roughTcM is a jewel in the rough
Default 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 To view attachments your post count must be 1 or greater. Your post count is 0 momentarily.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall


Business Directory | Technology Blog | Windows Help

Last edited by TcM; 12-02-2006 at 12:46 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 01-20-2007, 07:30 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 19
Posts: 2,352
Last Blog:
PHP Function Overloadi...
Rep Power: 50
John is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of light
Send a message via AIM to John
Default

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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-21-2007, 03:58 AM
xtraze xtraze is offline
Programming God
 
Join Date: Dec 2006
Location: Sri lanka
Posts: 921
Rep Power: 0
xtraze is on a distinguished road
Send a message via MSN to xtraze Send a message via Skype™ to xtraze
Default

I think it's because to make this work with all kinds of browsers. As some browsers ignore certain rules.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
JavaScript:Tutorial, Digital Clock TcM Javascript 10 06-06-2008 01:38 PM
JavaScript:Tutorial, Your First Game! TcM Javascript 31 06-06-2008 01:18 PM
JavaScript:Tutorial, Display MsgBox TcM Javascript 1 02-18-2007 08:55 PM
JavaScript:Tutorial, Loops TcM Javascript 4 12-13-2006 08:53 AM
JavaScript:Tutorial, Break Out Of Loops TcM Javascript 0 12-08-2006 05:35 AM


All times are GMT -5. The time now is 10:40 AM.

Contest Stats

dargueta ........ 93.00000
John ........ 87.50000
Xav ........ 50.00000
MeTh0Dz ........ 20.00000
gaylo565 ........ 18.00000
Johnnyboy ........ 3.00000

Contest Rules

Ads