View Single Post
  #1 (permalink)  
Old 12-02-2006, 09:18 AM
TcM's Avatar   
TcM TcM is offline
Moderator
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 8,317
Credits: 0
Rep Power: 74
TcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud of
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"> 
 do***ent.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 in this forum your post count must be 1 or greater. You currently have 0 posts.

Last edited by TcM; 12-02-2006 at 12:46 PM.
Reply With Quote

Sponsored Links