Jump to content

assign values to checkbox


ma5ect

Recommended Posts

HI all,

 

I have assigned a value to a check box but is it possible to have 2 values for one check box and then later display both values..

 

<input name="modulename[]" type="checkbox" value="<?php echo $row_Recordset2['Module name']; ?>" />
            <input type="checkbox" value="<?php echo $row_Recordset2['Scheduled']; ?>" name="modulename[]6" />

Link to comment
https://forums.phpfreaks.com/topic/134406-assign-values-to-checkbox/
Share on other sites

the short answer is no, unless you put both values into the value attribute of the one checkbox.  alternatively, you can manually specify the index of the element(s) so that you have a structured array sent back to you:

 

<input name="modulename[0][0]" type="checkbox" value="<?php echo $row_Recordset2['Module name']; ?>" />
<input name="modulename[0][1]" type="checkbox" value="<?php echo $row_Recordset2['Scheduled']; ?>" />

<input name="modulename[1][0]" type="checkbox" value="<?php echo $row_Recordset2['Module name']; ?>" />
<input name="modulename[1][1]" type="checkbox" value="<?php echo $row_Recordset2['Scheduled']; ?>" />

 

although to be honest, it's not clear what you're trying to achieve.  a bit more explanation might be in order if this doesn't help you.

Other alternatives:

 

- You can make the values a string with a separator like "val1|val2" and then explode at the |

 

- You can make one of the values the index name to modulename, if they are unique to each choice.

<input name="modulename[val1a]" type="checkbox" value="val2a" />

<input name="modulename[val1b]" type="checkbox" value="val2b" />

 

- You can have a hidden field for each checkbox named something associated with the checkbox (so you know which one to match it up to)

 

- Same thing as ^ but use sessions

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.