Wyatt
2006-04-04, 14:41
I'm working on a Javascript form validator, and I have a question. One of my form inputs is a set of radio buttons. How do I check to see that a selection has been made? Or, more specifically, how can I check to see that a certain selection has not been made? Here's what I have:
else if (document.joinform.paytype.value == 1)
{alert("You must select a payment type");
return false;}
Where a paytype value of 1 indicates the default value of "Select a payment type". Selection 2 is by check, and selection 3 is by PayPal.
<input type="radio" name="paytype" id="1" value="1" checked="checked" /><label for="1">Select a Payment Type</label><br />
<input type="radio" name="paytype" id="2" value="2" /><label for="2">Pay In Person</label><br />
<input type="radio" name="paytype" id="3" value="3" /><label for="3">PayPal</label>
As it is, the rest of my validator works except that one section. I thought I had everything right, but it doesn't work. It goes ahead and submits the form (which it should not do without a proper payment type selected).
else if (document.joinform.paytype.value == 1)
{alert("You must select a payment type");
return false;}
Where a paytype value of 1 indicates the default value of "Select a payment type". Selection 2 is by check, and selection 3 is by PayPal.
<input type="radio" name="paytype" id="1" value="1" checked="checked" /><label for="1">Select a Payment Type</label><br />
<input type="radio" name="paytype" id="2" value="2" /><label for="2">Pay In Person</label><br />
<input type="radio" name="paytype" id="3" value="3" /><label for="3">PayPal</label>
As it is, the rest of my validator works except that one section. I thought I had everything right, but it doesn't work. It goes ahead and submits the form (which it should not do without a proper payment type selected).