RSS
 

Posts Tagged ‘optional’

Make the radio buttons behave like single-choice checkboxes

27 Nov

If you a web developer, maybe you encountered this annoying thing.

Let’s say you need to write a list of choices, i.e. questions – answers. Let’s define that all the questions are optional and you can select just one answer per question. The way you should implement it, is using inputs with radio type, that’s fine and this how it should be.
Example code is:

1
2
3
4
5
6
7
8
9
10
11
<form method="post">
    <h4>What is favorite time?</h4>
    <label><input type="radio" name="question1" value="morning" /> Morning</label>
    <label><input type="radio" name="question1" value="noon" /> Noon</label>
    <label><input type="radio" name="question1" value="evening" /> Evening</label>
    <h4>What is your preferable paying method?</h4>
    <label><input type="radio" name="question2" value="cc" /> Credit Card</label>
    <label><input type="radio" name="question2" value="check" /> Check</label>
    <label><input type="radio" name="question2" value="paypal" /> Paypal</label>
    <label><input type="radio" name="question2" value="cash" /> Cash</label>
</form>

Read the rest of this entry »