Log in

View Full Version : Check box-- make it so only one box can be checked?



Humper
08-30-2006, 10:28 PM
I need to be able to only check one box for each question.. there is 3 choices for each questions but you can only select one of them... I cant seem to find out how to do this.. I tried to google it but I couldnt find an answer.. It has to be something simple

here are some of the questions

<tr><td> Phone Number:</td><td align="right"><input type="checkbox" name="GetPhone" value="Yes"> YES <input type="checkbox" name="GetPhone2" value="NO"> NO
<input type="checkbox" name="GetPhone3" value="NA" checked="checked"> NA</td></tr>

<tr><td> Email Address:</td><td align="right"><input type="checkbox" name="GetEmail" value="Yes"> YES <input type="checkbox" name="GetEmail2" value="NO"> NO
<input type="checkbox" name="GetEmail3" value="NA" checked="checked"> NA</td></tr>

<tr><td> IP Address:</td><td align="right"><input type="checkbox" name="GetIP" value="Yes"> YES <input type="checkbox" name="GetIP2" value="NO"> NO
<input type="checkbox" name="GetIP3" value="NA" checked="checked"> NA</td></tr>

mwinter
08-30-2006, 10:43 PM
I need to be able to only check one box for each question..

Then use the right tool: radio buttons.



<td align="right">

Use CSS (the text-align property, in this case), rather than the align attribute. Presentational markup should be avoided; those days are gone.



<input type="checkbox" name="GetPhone" value="Yes"> YES <input type="checkbox" name="GetPhone2" value="NO"> NO
<input type="checkbox" name="GetPhone3" value="NA" checked="checked"> NA

Change the type attribute value to "radio", and give each radio button the same name. You should also use the label element to associate each label with the appropriate control. For example:



<label><input type="radio" name="GetPhone" value="Yes"> YES</label>
<label><input type="radio" name="GetPhone" value="NO"> NO</label>
<label><input type="radio" name="GetPhone" value="NA" checked> NA</label>

A final note illustrated above: don't include the attribute value for boolean attributes like checked and selected. Just use the attribute name.

Mike

Humper
08-31-2006, 12:27 AM
Thank you very much!