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!!


LinkBack URL
About LinkBacks








Reply With Quote





Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum