I've really been racking my few brain cells on this one- It seems simple enough but I can't get it to work-
$(function() {
function check() {
var myname = $("#myname").val();
var myemail = $("#myemail").val();
var password = $("#password").val();
var repeatpassword = $("#repeatpassword").val();
if (myname == "") {
$("#mynameresult").append("Please Enter Your Name");
return false;
}
if (myemail =="") {
$("#myemailresult").append("Please Enter Your Email");
return false;
}
if (password == "") {
$("#passwordresult").append("Please Enter a Password");
return false;
}
if (repeatpassword == "") {
$("#repeatpasswordresult").append("Please Repeat the Password");
return false;
}
return true;
}
});
My form looks like this-
<table class="registrationform">
<form method="post" onsubmit = "return check();" action="/ToDoneList/ToDoneList/usr/registrationparse.php" enctype="multipart/form-data" >
<tr><td>Username: </td><td><input class="focusfox" type="text" name="username" id="myname"></td><td id="mynameresult"></td></tr>
<tr><td>Email: </td><td><input type="text" name="email" id="myemail"></td><td id="myemailresult"></td></tr>
<tr><td>Password: </td><td><input type="password" name="password" id="password" /></td><td id="passwordresult"></td></tr>
<tr><td>Repeat the Password: </td><td><input type="password" name="repeatpassword" id="repeatpassword"/></td><td id="repeatpasswordresult"></td></tr>
<tr><td rowspan="2"><img id="captcha" src="/securimage/securimage_show.php" alt="CAPTCHA Image" /></td><td><input type="text" name="captcha_code" maxlength="6" title="Enter What you see on the Left If you are having trouble click the New Image Button"/></td></tr>
<tr><td><button type="button "onclick=\'document.getElementById("captcha").src = "/securimage/securimage_show.php?" + Math.random(); return false\'>New Image</button></td>
<tr><td class="regbutton" colspan="2"><input type="submit" value="Register" ></td></tr>
</form>
</table>
The problem is that this function won't catch when I submit the form with empty spaces. I think it must be a problem with my if statements because when I strip it down and have it save values to the variables and append those values to the variables with return being false outside of an if statement it does stop it from submitting.
Anyway, is there anything that you can see that is wrong here? Thanks in advance for the help!
<form>inside a<table>like that. Also, always have your browser developer console open; you're getting an error currently.ifstatements? Don't you get an error in the Javascript console saying that the functioncheckis not defined?