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:-
And this in the <Body> tags:-Code:<SCRIPT language="JavaScript"> var visitorname= prompt('Please enter your name, ''); if ( (visitorname==' ') || (visitorname=="") || (visitorname==null) ) { visitorname="Man"; } </SCRIPT>
Explanation:-Code:<SCRIPT language="JavaScript"> document.write("<center>Hello, " + visitorname + "!<\center>"); </SCRIPT>
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..Code:if ( (visitorname==' ') || (visitorname=="") || (visitorname==null) ) { visitorname="Man"; }
A Preview:-
Conclusion:-
As Always Feedback is welcome and the full source is attached!!
Last edited by TcM; 12-02-2006 at 10:46 AM.
I'm just curious why you included all of this
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?Code:(visitorname==' ') || (visitorname=="") || (visitorname==null)
I think it's because to make this work with all kinds of browsers. As some browsers ignore certain rules.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks