How to Differentiate in groups of checkboxes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

How to Differentiate in groups of checkboxes

Post by itsmani1 »

Hi every One !

i have problem in fetching in retriving values using post method.
like here is some code:

Code: Select all

<form name="form1" method="post" action="2ndpage.php">
  <table width="100%" border="0" cellspacing="1" cellpadding="1">
    <tr> 
      <td> 
        <input name="1" type="checkbox" id="1" value="checkbox">
        one</td>
    </tr>
    <tr> 
      <td>
        <input name="2" type="checkbox" id="2" value="checkbox">
        two</td>
    </tr>
    <tr> 
      <td> 
        <input name="3" type="checkbox" id="3" value="checkbox">
        three</td>
    </tr>
    <tr> 
      <td>
        <input type="submit" name="Submit" value="Submit"></td>
    </tr>
  </table>
</form>
now on the 2ndpage.php

i want to fetch only thoese values that are checked
problme is that i have 2 types of check boxes
and i want to decide that the check box is checked or not and 2nd thing that i want to differentiate that checkbox belonges to which group.

Help Please ::
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

you should change the value parameter of input tag to reflect the group you want that checkbox in.

secondly change value="checkbox" to value="checkbox[]" so that an array of only selected checkboxes is sent.
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

n00b Saibot wrote:you should change the value parameter of input tag to reflect the group you want that checkbox in.

secondly change value="checkbox" to value="checkbox[]" so that an array of only selected checkboxes is sent.
thanks for the suggestion man 2nd thing is that i know there should be a name for checkbox that was just to show.
secondly change value="checkbox" to value="checkbox[]" so that an array of only selected checkboxes is sent.
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

-
Hi,

Code: Select all

<form name="form1" method="post" action="2ndpage.php"> 
  <table width="100%" border="0" cellspacing="1" cellpadding="1"> 
    <tr> 
      <td> 
        <input name="checkbox_type1&#1111;]" type="checkbox" id="1" value="checkbox"> 
        one</td> 
    </tr> 
    <tr> 
      <td> 
        <input name="checkbox_type1&#1111;]" type="checkbox" id="2" value="checkbox"> 
        two</td> 
    </tr> 
    <tr> 
      <td> 
        <input name="checkbox_type2&#1111;]" type="checkbox" id="3" value="checkbox"> 
        three</td> 
    </tr> 
    <tr> 
      <td> 
        <input name="checkbox_type2&#1111;]" type="checkbox" id="4" value="checkbox"> 
        three</td> 
    </tr> 
    <tr> 
      <td> 
        <input type="submit" name="Submit" value="Submit"></td> 
    </tr> 
  </table> 
</form>


With name="checkbox_typeX[]" you will get your data as ARRAY. Now you can check whether the checked data/box is in array_type1 or array_type2.

djot
-
Last edited by djot on Wed Feb 09, 2005 7:33 am, edited 1 time in total.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

does that solve ur prob or there is something else in this matter
Post Reply