I want to check the check box default which was already checked in the previous form

Discussion in 'PHP' started by smdrafiqq, Sep 20, 2010.

  1. #1
    Hi..!
    I am a fresher! Now 1ly I am started to learning php. I need to check some of the check box default in current form which was already selected in the previous form. For example, if i was select 3 of the check box among 5 check boxes , I need to show these three of the check box in checked condition and the remaining two will be unchecked..!

    I don't know how to express my doubt clearly..!Anyhow If anyone can understand my doubt means pls help me by send some sample codings..! Thank u..!
     
    smdrafiqq, Sep 20, 2010 IP
  2. Kakers

    Kakers Active Member

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    56
    #2
    Um, would you be able to explain this better ? :) Sorry just can't understand exactly what you need help with.
     
    Kakers, Sep 20, 2010 IP
  3. dreamconception

    dreamconception Peon

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If you use PHP you need to get the value in this way;

    
    if(isset($_POST['checkbox'])) $checked = " CHECKED";
    else $checked = "";
    
    echo '<input type="checkbox" name="checkbox"'.$checked.'>';
    
    Code (markup):
    This is not tested so might need a little fixing. Of course you then need to make it work with the 5 check boxes
     
    dreamconception, Sep 20, 2010 IP
  4. Kakers

    Kakers Active Member

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    56
    #4
    If you were to use the above code. Here is it with the result outside the php tags which would be helpful if you are putting it directly into another form.

    
    <?php
    if(isset($_POST['checkbox']))
    {
    $checked = "on";
    }
    else
    {
    $checked = "";
    }
    ?>
    
    <input type="checkbox" name="checkbox" value="<?php echo $checked; ?>" />
    
    Code (markup):
     
    Kakers, Sep 20, 2010 IP
  5. dreamconception

    dreamconception Peon

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Actually that is a better alternative Kakers, I recommend using that :)
     
    dreamconception, Sep 20, 2010 IP
  6. Kakers

    Kakers Active Member

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    56
    #6
    Couldn't have done it without your help haha, wasn't too sure what smdrafiqq wanted lol
     
    Kakers, Sep 20, 2010 IP