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
https://forums.phpfreaks.com/topic/60395-solved-array-of-checkboxes/
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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.