Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: radio buttons

  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Posts
    100
    Thanks
    1
    Thanked 0 Times in 0 Posts

    radio buttons

    I am coding a script that takes info from a database and displays it on a page. Right now there is a field in my database called "status" and I want the value in that field to be displayed in the form of radio buttons.

    Code:
    <input type=\"radio\" name=\"status\" value=\"{$row['status']}\" checked=\"checked\" /> Administrator
    &nbsp;&nbsp;<input type=\"radio\" name=\"status\" value=\"{$row['status']}\" checked=\"checked\" /> Manager
    &nbsp;&nbsp;<input type=\"radio\" name=\"status\" value=\"{$row['status']}\" checked=\"checked\" /> Moderator
    So if "Administrator" is placed in the "status" field, then the Administrator button would be selected.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    The value for radio buttons should be static, and you set the correct one to checked based on the current value in $row:
    PHP Code:
    echo "<input type=\"radio\" name=\"status\" value=\"Administrator\" " . ($row['status'] == 'Administrator' ' checked="checked"' '') . "/> Administrator&nbsp;&nbsp;
    <input type=\"radio\" name=\"status\" value=\"Manager\" " 
    . ($row['status'] == 'Manager' ' checked="checked"' '') . "/> Manager&nbsp;&nbsp;
    <input type=\"radio\" name=\"status\" value=\"Moderator\" " 
    . ($row['status'] == 'Moderator' ' checked="checked"' '') . "/> Moderator"


  •  

    Posting Permissions

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