Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prompt box question regarding the cancel button? 1

Status
Not open for further replies.

UncleMortis

Programmer
Jan 28, 2003
120
AU
I've made a site and I've included a prompt when the site loads so that someone can put their name in and it will welcome them by name, if they fill it out of course. If they press OK without filling it out, it's fine, but if they press cancel, it returns NULL. How can I avoid it returning null?
 
You can't avoid it returning null. However you can test the result and handle those instances where it returns null.

eg
[tt]
var strUserName = prompt('Who the hell are you?','');
if((strUserName == null) || (strUserName == '')){
strUserName = "O Great Nameless One";
}
[/tt]

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top