This is the javascript code that i have for validating a form, it raises error if the user puts in invalid information. The problem im having is when i enter:
- /* if(title.checked=false){
-
inlineMsg('radio', 'You must select a title.',2);
-
return false;
-
*/
it brakes the code, but when i comment out the rest works fine?????
- function validate(form) {
-
var name = form.name.value;
-
var email = form.email.value;
-
var title = form.title.value;
-
var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
-
var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
-
var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
-
/* if(title.checked=false){
-
inlineMsg('radio', 'You must select a title.',2);
-
return false;
-
}*/
-
if(name == "") {
-
inlineMsg('name','You must enter your name.',2);
-
return false;
-
}
-
if(!name.match(nameRegex)) {
-
inlineMsg('name','You have entered an invalid name.',2);
-
return false;
-
}
-
if(email == "") {
-
inlineMsg('email','<strong>Error</strong><br />You must enter your email.',2);
-
return false;
-
}
-
if(!email.match(emailRegex)) {
-
inlineMsg('email','<strong>Error</strong><br />You have entered an invalid email.',2);
-
return false;
-
}
-
-
return true;
-
}
HTML
Here is Html for the radio buttons
-
<label>Mr:
-
<input name="title" value="Mr" type="radio" />
-
</label>
-
<label> Ms:
-
<input name="title" value="Ms" type="radio" />
-
</label>
-
<label> Mrs:
-
<input name="title" value="Mrs" type="radio" />
-
</label>
-
<label> Dr:
-
<input name="title" value="Dr" type="radio" />
-
</label>