Results 1 to 3 of 3

Thread: Help with Radio buttons

  1. #1
    Join Date
    Feb 2009
    Posts
    27
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question Help with Radio buttons

    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.

  2. #2
    Join Date
    Nov 2008
    Posts
    58
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Default

    This is the HTML code for the radio buttons:
    Code:
    <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

  3. #3
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    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.
    Code:
    <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.
    PHP Code:
    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
    - Josh

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •