I'm trying to validate a textbox when certain letters are entered, For example, if b,c,d,e,g,y, or z are entered in the textbox a message will display - "Tell me why you entered this letter". Then it should focus in a textarea to explain why they entered one of those letters. After they explain why they entered that letter, the form should submit.
If they enter a letter besides b,c,d,e,g,y, or z the form should submit without focusing on the textarea for a comment.
There has to be a better way to write the IF statement. Instead of writing all the IF statements below, how?
This is what I have so far. Please show me how to do this the right way. Thanks
<SCRIPT language="JavaScript">
function TheForm () {
var errors = "";
if (document.submitForm.lette
rs.value == "b"){
errors += "\n\tLetter - Tell me why you entered this letter. \n";
}
if (document.submitForm.lette
rs.value == "c"){
errors += "\n\tLetter - Tell me why you entered this letter. \n";
}
if (document.submitForm.lette
rs.value == "d"){
errors += "\n\tLetter - Tell me why you entered this letter. \n";
}
if (document.submitForm.lette
rs.value == "e"){
errors += "\n\tLetter - Tell me why you entered this letter. \n";
}
if (document.submitForm.lette
rs.value == "g"){
errors += "\n\tLetter - Tell me why you entered this letter. \n";
}
if (document.submitForm.lette
rs.value == "y"){
errors += "\n\tLetter - Tell me why you entered this letter. \n";
}
if (document.submitForm.lette
rs.value == "z"){
errors += "\n\tLetter - Tell me why you entered this letter. \n";
}
<!--There has to be a better way to write the IF statement. Instead of writing all these IF statements, how?-->
if (errors != ""){
errors += alert(msg + errors + "\n\n");
return false;
}
return true;
}
</script>
<form method="post" name="submitForm" action="send.asp" onSubmit="return TheForm();">
<input name="letters1" type="text" id="letters">
<textarea name="theComments" cols="80" rows="12"></textarea>
</form>