emilyly111
06-23-2009, 06:53 PM
I am trying to write a validation script for a form question that requests an explanation (in a text box) if a particular radio button is selected:
4. Do you communicate directly with others you met via message boards? (e.g., by email, instant messenger, phone, etc) NO YES
If yes, please specify the mode of communication:
Current script is:
radioOption = -1;
for (i=0; i<document.forms[0].question4.length; i++) {
if (document.forms[0].question4.checked) {
radioOption = -1;
break;
}
}
if (radioOption == -1) {
window.alert ('You didn\'t finish answering Question 4');
return false;
}
if (document.forms[0].question4.checked == true && document forms[0].question4_explain.value == "") {
window.alert ('You didn't specify the type of communication in question 4!');
return false;
}
How do I change this last part to be specific to value 2 for the radio button rather than any value selection requires an explanation? (how do I require that the text box be completed only if yes is selected?)
4. Do you communicate directly with others you met via message boards? (e.g., by email, instant messenger, phone, etc) NO YES
If yes, please specify the mode of communication:
Current script is:
radioOption = -1;
for (i=0; i<document.forms[0].question4.length; i++) {
if (document.forms[0].question4.checked) {
radioOption = -1;
break;
}
}
if (radioOption == -1) {
window.alert ('You didn\'t finish answering Question 4');
return false;
}
if (document.forms[0].question4.checked == true && document forms[0].question4_explain.value == "") {
window.alert ('You didn't specify the type of communication in question 4!');
return false;
}
How do I change this last part to be specific to value 2 for the radio button rather than any value selection requires an explanation? (how do I require that the text box be completed only if yes is selected?)