Jonathan Harvey Posted July 25, 2009 Share Posted July 25, 2009 Below I have a simple Javascript form validation. I know that it's not very complicated and won't check the password but it's just to practice javascript. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Registration</title></head><body><script type="text/javascript">//lets validate the form, note it didn't work before because I called a function before I defined it.//lets alert the user and return and call whats_missing, so we can return a value to the formfunction alertuser(missing, missingalert) { alert("please fix " + missingalert); return false; //function to check whats missing, or if email be screwed upfunction whats_missing(){ if(document.register.username.value == null||"") { missing = username; alertuser(missing, "Please fix " + missing) return false; } else if(document.register.password.value == null||"")( missing = password alertuser(missing, "Please fix " + missing) return false;} else { return true; } }</script><form name="register" action="thanksforregistering.html" method="post" onSubmit="return whats_missing()"><input type="text" name="username" size="20" /><input type="password" name="password" size="20" /><input type="submit" value="Sign up" /></form></body></html> When I run this code with no username nothing happens. can somebody tell me what I'm doing wrong? Thanks! Link to comment Share on other sites More sharing options...
Ingolme Posted July 25, 2009 Share Posted July 25, 2009 You have forgotten to close this function, therefore, all the functions that follow it won't exist because they're considered to be inside this one and this one returns on the second line. You're not doing anything with the "missing" parameter function alertuser(missing, missingalert) {alert("please fix " + missingalert);return false;//function to check whats missing, or if email be screwed upfunction whats_missing(){ Link to comment Share on other sites More sharing options...
Jonathan Harvey Posted July 25, 2009 Author Share Posted July 25, 2009 You have forgotten to close this function, therefore, all the functions that follow it won't exist because they're considered to be inside this one and this one returns on the second line. You're not doing anything with the "missing" parameter function alertuser(missing, missingalert) {alert("please fix " + missingalert);return false;//function to check whats missing, or if email be screwed upfunction whats_missing(){ I fixed the missing parameter right after this I noticed it, but I guess I didn't notice I forget to close the function. Thanks for the help! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.