Hi.
I have had several threads about validating my textarea; for some reason it won't validate. The function that validates doesn't seem to be called at all.
Here is the form simplified:
<form name="annonsera" id="annonsera" method="post"
enctype="multipart/form-data" onSubmit="return validateForm();">
<textarea name="annonsera_des" cols="45" rows="12" id="annonsera_des"></textarea>
</form>
And here is the Javascript that gets the form textarea's value:
var description = document.getElementById("annonsera_des");
And here is the javascript that calls the function to validate all fields etc...
function validateForm() {
var name = document.getElementById("annonsera_name");
var tel = document.getElementById("annonsera_tel");
var email = document.getElementById("annonsera_email");
var area = document.getElementById("annonsera_area");
var community = document.getElementById("annonsera_area_community");
var category = document.getElementById("annonsera_category");
var subcats = document.getElementById("annonsera_subcats").getElementsByTagName("select");
var headline = document.getElementById("annonsera_headline");
var description = document.getElementById("annonsera_des");
if (nameValid(name)){
if (telValid(tel)){
if (emailValid(email)){
if (areaValid(area)){
if (communityValid(community)){
if (categoryValid(category)){
if (subcatsValid(subcats)){
if (headlineValid(headline)){
if(descriptionValid(des)){
return true;
}
}
}
}
}
}
}
}
}
return false;
}
And here is the function descriptionValid():
function descriptionValid(fld){
if (fld.value=="") {
document.getElementById("annonsera_descriptionempty_error").style.display='block';
document.getElementById("annonsera_description").focus();
document.getElementById("annonsera_descriptionshort_error").style.display='none';
return false;
}
else if (fld.value.length<3){
document.getElementById("annonsera_descriptionshort_error").style.display='block';
document.getElementById("annonsera_description").focus();
document.getElementById("annonsera_descriptionempty_error").style.display='none';
return false;
}
document.getElementById("annonsera_descriptionempty_error").style.display='none';
document.getElementById("annonsera_descriptionshort_error").style.display='none';
return true;
}
So, what is wrong with this code?
NOTE: I have added alert boxes inside the descriptionValid() function, and none of them get displayed, so basically the function doesn't get called for some reason. The form just submits. The strange part is that I am validating all other fields and drop lists using exactly the same method and it works fine.