Jump to content

making an array from checkbox


Recommended Posts

how can i make an array from checkboxes? and pass it to another php page?

Edited by birbal
Link to post
Share on other sites

When submitted, the checkboxes will come in as an array without you having to do anything. If your checkboxes are named "box", then this:$boxlist = $_POST[box'];...will produce an array of the checkboxes named "$boxlist".

Link to post
Share on other sites

no no..not so..i am not tellin to catch a input checkbox value as arrayi was talking about how can i take multiple checkbox value as an array?something like

<input type="checkbox" name="somename" value="" /><input type="checkbox" name="somename1" value="" /><input type="checkbox" name="somename2" value="" /><input type="checkbox" name="somename3" value="" />...........................so on

here somename1/2/3 both are same kind of instances of a object. i want to catch all checkbox values in a array and send it back to other page

Link to post
Share on other sites

If you name all your checkboxes look like this:<input type="checkbox" name="box[]" value="something">then you will find an array in $_POST['box']. This works because we are exploiting PHP's auto-iterating feature.You will of course have to determine what these items represent from their values alone, since the key ("box") does nothing to distinguish one checkbox from another, and the array is indexed numerically. I mean, the array won't have an empty element if a checkbox is not checked. If boxes 0, 1, and 4 are checked, you'll have values in $_POST['box'][0], $_POST['box'][1], and $_POST['box'][2].

Edited by Deirdre's Dad
Link to post
Share on other sites
If you name all your checkboxes look like this:<input type="checkbox" name="box[]" value="something">then you will find an array in $_POST['box']. This works because we are exploiting PHP's auto-iterating feature.You will of course have to determine what these items represent from their values alone, since the key ("box") does nothing to distinguish one checkbox from another.
thats what i was talking about. i did not think it can be do like this easy way using 2D array. i was thinking it more complexly than this.realy thank you very much deirdre's dad. Edited by birbal
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...