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 checked

  1. #1
    New Coder
    Join Date
    May 2010
    Posts
    23
    Thanks
    9
    Thanked 0 Times in 0 Posts

    radio checked

    Hey everybody! My current code works, but it is messy and seems too long. I am just asking for help to abridge and make it a little more concise. I am checking the status of a radio button preset against a mySQL table. For about ten fields their status can be (none, display, require)

    PHP Code:

                
    function checkFields($field_num$ch1$ch2$ch3)
                {
                    if(
    $field_num == "none")
                    {
                        
    $ch1 'checked'
                    
    }
                    else if(
    $field_num == "display")
                    {
                        
    $ch2 'checked'
                    
    }
                    else if(
    $field_num == "require")
                    {
                        
    $ch3 'checked'
                    
    }
                    else
                        
    $ch1 'checked'
                
    }
    //Ten of these:
    function($fieldsArray[1], $fname1$fname2$fname3); 
    Then on the radio buttons this requires me to have 3 php variables for each each set to ' '. This was the best I could come up with. Possibly if there was a way to select radio->specific name->specific value = 'checked' ... Any ideas?

  • #2
    New Coder
    Join Date
    Apr 2010
    Posts
    38
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Grouping check box as per below mentioned html and saving $status as shown may help on what is needed.

    <?php
    if(isset($_POST['save']) && $_POST['save'] != ''){
    $status = $_POST['chkname'];
    // then update mysql database tables with this status
    }
    ?>
    <form action="page5.php" method="post">
    <input type="checkbox" name="chkname" value="none">
    <input type="checkbox" name="chkname" value="display">
    <input type="checkbox" name="chkname" value="require">
    <input type="submit" name="save" value="save">
    </form>


  •  

    Posting Permissions

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