SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict user_A's Avatar
    Join Date
    Mar 2004
    Location
    Vancouver, BC
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Update two radio buttons

    Hi guys,

    I'm having truble to update my profile page that has two radio buttons for gender selection, one for male and the other for female, I've got the update function to work based on the selection, but I can't figure out how to update the radio button so that once a user returns to their profiles page, the correct selected radio button would be selected, instead now both appear un-selected.

    Here's my code.

    PHP Code:
    <?php
          $male_status 
    'unchecked';
          
    $female_status 'unchecked';

          if (isset(
    $_POST['Submit1'])) {
           
    $selected_radio $_POST['gender'];
        
            if (
    $selected_radio == 'male') {
                
    $male_status 'checked';
            }
            else if (
    $selected_radio == 'female') {
                
    $female_status 'checked';
            }
            }
        
    ?>

    HTML Code:
     <p>Male:</p> 
          <input id="mgender" name="gender" title="Gender Type: Male" type="radio" value="male" <?php echo $male_status; ?>/>
    
          <p>Female:</p> 
          <input id="fgender" name="gender" title="Gender Type: Female" type="radio" value="female" <?php echo $female_status; ?>/>
        </div>

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I normally do something like this:
    PHP Code:
    <?php
    $gender 
    = isset($_POST['gender']) ? $_POST['gender'] : ''
    ?>
    <p>Male:</p> 
    <input id="mgender" name="gender" title="Gender Type: Male" type="radio" value="male"<?php echo ($gender == 'male') ? ' checked=""' ''?> />
    <p>Female:</p> 
    <input id="fgender" name="gender" title="Gender Type: Female" type="radio" value="female"<?php echo ($gender == 'female') ? ' checked=""' ''?> />
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    SitePoint Addict user_A's Avatar
    Join Date
    Mar 2004
    Location
    Vancouver, BC
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But my field type in `gender` enum('Male','Female')

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by user_A View Post
    But my field type in `gender` enum('Male','Female')
    Then just update the radio button values to capital Male and Female. Is there any problem? The way what I am using is quite enough AFAIK.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    SitePoint Addict user_A's Avatar
    Join Date
    Mar 2004
    Location
    Vancouver, BC
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That was exactly the problem, thank you!

  6. #6
    Non-Member
    Join Date
    Dec 2010
    Location
    New york
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you have try to put checked =true in html code? it might be work. no need to put condition in php code.

  7. #7
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by user_A View Post
    That was exactly the problem, thank you!
    Do you mean that solved the problem?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


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
  •