ksmatthews Posted September 27, 2007 Share Posted September 27, 2007 Hi there, I am OK using php to process ARRAYS of checkboxes BUT how on earth can you process multiple checkboxes with the SAME name WITHOUT using arrays ? For example ... <input name = "check" type = "checkbox" value = "'value1'"/> <input name = "check" type = "checkbox" value = "'value2'"/> <input name = "check" type = "checkbox" value = "'value3'"/> as opposed to ... <input name = "check[]" type = "checkbox" value = "'value1'"/> <input name = "check[]" type = "checkbox" value = "'value2'"/> <input name = "check[]" type = "checkbox" value = "'value3'"/> The problem is that you cannot use checkbox arrays (of the form check[]) in javascript. There seems to a conflict of interest here ? regards, Steven M Link to comment https://forums.phpfreaks.com/topic/70890-multiple-checkboxes/ Share on other sites More sharing options...
rarebit Posted September 27, 2007 Share Posted September 27, 2007 <input name = "check[value1]" type = "checkbox" value = "'value1'"/> Link to comment https://forums.phpfreaks.com/topic/70890-multiple-checkboxes/#findComment-356345 Share on other sites More sharing options...
MadTechie Posted September 27, 2007 Share Posted September 27, 2007 Review the Javascript code as Javascript CAN use <input name = "check[]" type = "checkbox" value = "'value1'"/> EDIT: example <form action="" name="myform"> dep 1<input type="checkbox" name="department[]" value="1" onclick="checkall(this)"><br> emp 1<input type="checkbox" name="dep1_employee[]" value="1"><br> emp 2<input type="checkbox" name="dep1_employee[]" value="2"><br> emp 3<input type="checkbox" name="dep1_employee[]" value="3"><br> <br> dep 2<input type="checkbox" name="department[]" value="2" onclick="checkall(this)"><br> emp 4<input type="checkbox" name="dep2_employee[]" value="4"><br> emp 5<input type="checkbox" name="dep2_employee[]" value="5"> </form> <script type="text/javascript"> function checkall(dep) { var empls = document.myform['dep' + dep.value + '_employee[]']; for (var i = 0; i < empls.length; i++) { empls[i].checked = dep.checked? true : false; } } </script> Link to comment https://forums.phpfreaks.com/topic/70890-multiple-checkboxes/#findComment-356349 Share on other sites More sharing options...
ksmatthews Posted September 27, 2007 Author Share Posted September 27, 2007 Thanks Madtechie, Can you please explain how your function works .... function checkall(dep) { var empls = document.myform['dep' + dep.value + '_employee[]']; for (var i = 0; i < empls.length; i++) { empls.checked = dep.checked? true : false; } } What is dep ? regards, Steven M Link to comment https://forums.phpfreaks.com/topic/70890-multiple-checkboxes/#findComment-356380 Share on other sites More sharing options...
MadTechie Posted September 27, 2007 Share Posted September 27, 2007 you have 2 groups dep1_employee[] and dep2_employee[], the script gets the value from the option selected (1 or 2) thus dep = X (1 or 2) make sense ? Link to comment https://forums.phpfreaks.com/topic/70890-multiple-checkboxes/#findComment-356399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.