Jump to content

multiple checkboxes


ksmatthews

Recommended Posts

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

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

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

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.