checkbox array

Discussion in 'PHP' started by Balamurali, Jul 13, 2008.

  1. #1
    <form name="myform" action="" method="post">
    <input type=hidden name=keyword>
    <b>Scripts for Web design and programming</b><br>
    <input type="checkbox" name="check_list" value="1">ASP<br>
    <input type="checkbox" name="check_list" value="2">PHP<br>
    <input type="checkbox" name="check_list" value="3">JavaScript<br>
    <input type="checkbox" name="check_list" value="4">HTML<br>
    <input type="checkbox" name="check_list" value="5">MySQL<br>

    <input type="button" name="Check_All" value="Check All"
    onClick="Check(document.myform.check_list)">
    <input type=submit>
    </form>
    function Check(chk)
    {
    if(document.myform.Check_All.value=="Check All"){
    for (i = 0; i < chk.length; i++)
    chk.checked = true ;
    document.myform.Check_All.value="UnCheck All";
    }else{

    for (i = 0; i < chk.length; i++)
    chk.checked = false ;
    document.myform.Check_All.value="Check All";
    }
    }
    <?php
    if(isset($_REQUEST['keyword']))
    {
    $val=$_REQUEST['check_list'];
    print_r($val);
    }
    ?>
    //Here i got the value 5. I mean i can get only at the last value.
    How can i get all checkbox values?

     
    Balamurali, Jul 13, 2008 IP
  2. King Goilio

    King Goilio Member

    Messages:
    200
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    33
    #2
    checkboxs don't work like that you have to have them all different names.
     
    King Goilio, Jul 14, 2008 IP
  3. 2slick

    2slick Peon

    Messages:
    73
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    the easiest trick would be using an onsubmit on the form and process those id's as csv, pass them to a form variable.
     
    2slick, Jul 14, 2008 IP
  4. Balamurali

    Balamurali Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I could not get you what you mean to say.
     
    Balamurali, Jul 14, 2008 IP
  5. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #5
    Perhaps what he meant?

    <input type="checkbox" name="check_list[]" value="1">ASP<br>
    <input type="checkbox" name="check_list[]" value="2">PHP<br>
    <input type="checkbox" name="check_list[]" value="3">JavaScript<br>
    <input type="checkbox" name="check_list[]" value="4">HTML<br>
    <input type="checkbox" name="check_list[]" value="5">MySQL<br>
    HTML:
     
    Danltn, Jul 14, 2008 IP