prometheos Posted March 25, 2010 Share Posted March 25, 2010 Hi, i have 2 arrays of checkboxes and i want it so that when i check 1, the same index of the other 1 is unchecked... any ideas how to do this? here's the way i have it set up? if(($xml->item[$n-1]->requested->confirmed == "") &&($xml->item[$n-1]->requested->by != "") ){ echo '<td><center><input type="checkbox" name="confirmItems[]" value="'.$itemString.' onCheck = " " "/></center></td>'; echo '<td><center><input type="checkbox" name="denyItems[]" value="'.$itemString.'"/></center></td>'; } What should i do in the onCheck? this is inside a foreach loop by the way. thanks for the help Link to comment https://forums.phpfreaks.com/topic/196486-html-oncheck-checkboxes-in-php/ Share on other sites More sharing options...
tekrscom Posted March 25, 2010 Share Posted March 25, 2010 You need JavaScript help, not PHP... Link to comment https://forums.phpfreaks.com/topic/196486-html-oncheck-checkboxes-in-php/#findComment-1031678 Share on other sites More sharing options...
andrewgauger Posted March 25, 2010 Share Posted March 25, 2010 I don't know why you are using an array to define the checkboxes, but that is the fist change I'd make: <input type="checkbox" name="confirmItems" value="'.$itemString.' onCheck = " " "/> Then I'd take into consideration that not all browsers will display the value="" portion: <input type="checkbox" name="confirmItems[]" value="'.$itemString.' onCheck = " " ">'.$itemString.'</input> Then the javascript you need would look like: <script language="javascript"> function uncheck(src,element) { if (src.checked==true) { element.checked=false } } </script> <form name="request"> <input type="checkbox" name="confirm" onClick="uncheck (this,document.request.deny)">confirm</input> <input type="checkbox" name="deny" onClick="uncheck(this,document.request.confirm)">deny</input> </form> [code] I didn't bother to convert this into php, so when you copy and paste put it into a htm file and then make the mods to get it going in php. The only difference between this and a radio object is that once you select one, you can make the decision to clear both--if this is not the behavior you want look into the radio object. Link to comment https://forums.phpfreaks.com/topic/196486-html-oncheck-checkboxes-in-php/#findComment-1031686 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.