Why won't JavaScript alert box work in this example? -
i trying validate 3 fields in html form using javascript. if of fields empty alert box appears message indicating fields empty. works fine. i'm having problem getting message (msg2) appear in alert box when form has been completed properly. code below-i know it's simple i'm missing if can help. thanks!
var valid = true; var msg="incomplete form:\n"; var msg2="success! there no null fields."; if ( myname== "" ) { msg+="you need fill name field!\n"; valid = false; } if ( emailaddress == "" ) { msg+="you need fill in email!\n"; valid = false; } if ( commentstring == "" ) { msg+="you need fill in comment!\n"; valid = false; } if ((!myname=="")&&(!emailaddress=="")&&(!commentstring=="")){ return msg2; } if (!valid) alert(msg); return valid; }
you're right, it's simple: return msg2;
not open alert box. still have call alert()
somewhere.
Comments
Post a Comment