victaru
07-20-2009, 10:37 AM
Hi all,
I'm currently working on a PHP project, in which i have a search form for users to set search criteria and displays the result. for each result row i have created a checkbox for the user to select that row such that they will be able to identify which rows to export out.
now, as this could be a potentially generate a huge list of results, individually selecting each checkbox can be a pain. so i created a "toggle" checkbox which will toggle the checkboxes "on" or "off" using a javascript function.
the HTML code for the "toggle"
<INPUT TYPE='checkbox' NAME='AutoCheck' VALUE='Autocheck-uncheck All Boxes' onClick='modify_boxes()'>
and the code for each of the individual checkboxes
<input type='checkbox' name='expID[]' value='" . $info['ID'] . "'>
the JS function
function modify_boxes(){
for ( i=0 ; i <theForm.elements.length ; i++ ){
if (theForm.elements[i].name=='expID[]'){
if (theForm.AutoCheck.checked == true) {
theForm.elements[i].checked = true;
}else{
theForm.elements[i].checked = false;
}
}
}
}
now, as this could be a potentially generate a huge list of results, looping through all the form elements looping through all the elements in the form seems inefficient (i have many other elements besides this checkbox), is there another way to achieve the same result (i.e. autocheck/uncheck) in a more effective manner?
Thanks in advance!
I'm currently working on a PHP project, in which i have a search form for users to set search criteria and displays the result. for each result row i have created a checkbox for the user to select that row such that they will be able to identify which rows to export out.
now, as this could be a potentially generate a huge list of results, individually selecting each checkbox can be a pain. so i created a "toggle" checkbox which will toggle the checkboxes "on" or "off" using a javascript function.
the HTML code for the "toggle"
<INPUT TYPE='checkbox' NAME='AutoCheck' VALUE='Autocheck-uncheck All Boxes' onClick='modify_boxes()'>
and the code for each of the individual checkboxes
<input type='checkbox' name='expID[]' value='" . $info['ID'] . "'>
the JS function
function modify_boxes(){
for ( i=0 ; i <theForm.elements.length ; i++ ){
if (theForm.elements[i].name=='expID[]'){
if (theForm.AutoCheck.checked == true) {
theForm.elements[i].checked = true;
}else{
theForm.elements[i].checked = false;
}
}
}
}
now, as this could be a potentially generate a huge list of results, looping through all the form elements looping through all the elements in the form seems inefficient (i have many other elements besides this checkbox), is there another way to achieve the same result (i.e. autocheck/uncheck) in a more effective manner?
Thanks in advance!