[thelist] Javascript validation help....HELP!!

Michael Pack michaelpack at wvdhhr.org
Thu Aug 17 10:02:02 CDT 2006


Hello all, I've been working on something I thought would be simple but
has turned out to be a nightmare. Can any Javascript guru's help me out
please? I need the value of a radio set and need to use the value within
my validation statement. I'm not getting errors, the logic (as I see it)
just isn't working. I simply want to say in my validation script
"Alert.... If the user selected the Yes radio button but has not checked
an age group"  My latest go at it....

CODE

<div class="row">
	<span class="label">Do you want to provide care for
children?</span>
	<span class="formw"><input type="radio" name="Children"
value="Yes" id="Children_yes" /><label
for="Children_yes">Yes</label>&nbsp;
			     <input type="radio" name="Children"
value="No" id="Children_no" /><label
for="Children_no">No</label></span>
</div>

<div class="row">
	<span class="label">If yes, what age of child would you be
interested in providing care for?</span>
	<span class="formw"><input type="checkbox" name="AgeInterest"
value="Infant to 3 years" id="AgeInterest1" /><label
for="AgeInterest1">Infant to 3 years old</label></span>
	<span class="formw"><input type="checkbox" name="AgeInterest"
value="3 to 5 years" id="AgeInterest2" /><label for="AgeInterest2">3 to
5 years old</label></span>
	<span class="formw"><input type="checkbox" name="AgeInterest"
value="5 to 10 years" id="AgeInterest3" /><label for="AgeInterest3">5 to
10 years old</label></span>
	<span class="formw"><input type="checkbox" name="AgeInterest"
value="10 to 15 years"id="AgeInterest4" /><label for="AgeInterest4">10
to 15 years old</label></span>
	<span class="formw"><input type="checkbox" name="AgeInterest"
value="15 to 18 years" id="AgeInterest5"/><label for="AgeInterest5">15
to 18 years old</label></span>
</div>

<input type="submit" value="Submit Your Inquiry Form" name="Submit"
onclick="get_Children_value()"  />

FUNCTION

function get_Children_value()
{
for (var i=0; i < document.sfcp_inquiry.Children.length; i++)
   {
   if (document.sfcp_inquiry.Children[i].checked)
      {
      var Children_val = document.sfcp_inquiry.Children[i].value;
      }
   }
}


VALIDATION

 if (!(theForm.AgeInterest[0].checked && Children_val == "Yes" ||
theForm.AgeInterest[1].checked && Children_val == "Yes" ||
theForm.AgeInterest[2].checked && Children_val == "Yes" ||
theForm.AgeInterest[3].checked && Children_val == "Yes" ||
theForm.AgeInterest[4].checked && Children_val == "Yes" )) { 
 alert("You specified that you would be interested in providing care
for children but you did not specify what ages of children you would be
interested in. Please make a selection."); 
 theForm.AgeInterest[0].focus();
 return false; 
}

TIA!!





More information about the thelist mailing list