Jump to content

[SOLVED] array of checkboxes


black.horizons

Recommended Posts

hi all,

 

i have a datagrid (several columns of arrays). submitting values from textboxes is fine, as submitted values are related to each row (i.e. for row1 if text entered is "boo" then that is what is returned for row1.) however i have tried to implement checkboxes and have discovered that if you tick the box for row 5 and non of the four preceding rows, then what is returned says row1 has the box ticked. this i gather is from the checkbox not submitting a value if it is not ticked. is there a way round this?

 

that explanation was totally pants, and if anybody understands it i for one will be amazed!!

 

tia - alex

Link to comment
Share on other sites

the problem is exactly as you suspect - a checkbox will only send its value if it is checked.  to amend this, you'll probably either want to explicitly state the array key in the name of the checkbox, or specify the unique indentifier in the value it passes back:

 

<input type="checkbox" name="ticked[5]" value="row5" />

 

by the way, have a look around - there are people FAR worse at explaining their problem than you.

Link to comment
Share on other sites

worked a treat. i had the rows displaying in a foreach loop - as the number of rows was determined frmo the number of results returned from a mysql table. for anybody else with a similar problem in future after the "while" line put "$i=0;" at the end of your foreach loop (i.e. before the "}" put "$i++;". Insert " <input type="checkbox" name="ticked[$i]" " where appropriate.

 

Many thanks akitchin. I knew what I needed and what the problem was, just wasn't aware I could state the array key explicitly. Come to think of it I should have known this ... no matter.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.