Log in

View Full Version : Help with Radio buttons



MSK7
08-24-2009, 07:03 AM
Hello all ,

I am using a while query to fetch rows from DB in a form .

I want to apply three Radio buttons called 'A', 'B', 'C' .

That is to be displayed in each rows fetched from DB.

and required that one of the radiobutton from the

three radio button ,

called 'A', to be displayed checked On in all the rows fetched

from DB.

'B' & 'C' radiobuttons can be checked On by user if required

in each rows.

if B or C is checked by user then one of them get checked On

and the option A is automatically checked Off for that row.



Please help me in how these can be applied .


Thanks & Regards.

prasanthmj
08-24-2009, 11:06 AM
This is the HTML code for the radio buttons:

<input type='radio' name='RadioGroup' value='a' checked>a
<input type='radio' name='RadioGroup' value='b' tabindex='1'>b
<input type='radio' name='RadioGroup' value='c' tabindex='2'>c

You have to write the PHP code to fetch from the DB

JShor
08-24-2009, 03:06 PM
That's more complicated, one of the radio buttons will have to be of different name than B & C. You'd need to use javascript for this.

This is the javascript. Insert this wherever in the HTML you want.


<script type="text/javascript">
function chkState() {
var a = document.getElementById('a');
var b = document.getElementById('b');
var c = document.getElementById('c');

if(a.checked = true) {
b.checked = false;
c.checked = false;
}

if(b.checked = true) {
a.checked = false;
}

if(c.checked = true) {
a.checked = false;
}

}
</script>


This is a sample while statement. Include the echo in your while statement.


while($this => $that) { // sample while statement

echo '
<input type="checkbox" name="a" value="a" id="a" checked="checked"><label for="a">A</label>
<input type="checkbox" name="b" value="b" id="b"><label for="b">B</label>
<input type="checkbox" name="c" value="c" id="c"><label for="c">C</label>
';

} // end while statement


For each value in while that occurs, the checkboxes will be repeated. When {a} is checked, {b} and {c} will be unchecked. When {b} or {c} are checked, {a} will be unchecked.

HTH:)