xProteuSx Posted January 20, 2012 Share Posted January 20, 2012 I've got a PHP generated form which generates x amount of checkboxes, dependent on the number of values in an array. Hence, if there are three items in an array, three checkboxes are generated in the following manner: <form name="markform" method="post" action="somepage.html"> <input type="checkbox" name="marked[]" value="1" /> <input type="checkbox" name="marked[]" value="2" /> <input type="checkbox" name="marked[]" value="3" /> <img src="images/btn_check_all.png" onClick="checkAll()" /><br /> //check all boxes <img src="images/btn_uncheck_all.png" onClick="uncheckAll()" /><br /> //uncheck all boxes <input type="image" src="images/btn_update.png" /> //submit button </form> Now, if it wasn't for the fact that name="marked[]" is a javascript array, then my problem wouldn't be a problem. I could just do this: <SCRIPT LANGUAGE="JavaScript"> function checkAll() { var field = 'document.markform.marked'; for (i = 0; i < field.length; i++) field.checked = true ; } function uncheckAll() { var field = 'document.markform.marked'; for (i = 0; i < field.length; i++) field.checked = false ; } </script> However, this does not seem to work: var field = 'document.markform.marked[]'; How can I create 'Check All / Uncheck All' buttons when my input field name is an array?? Thanks. Link to comment https://forums.phpfreaks.com/topic/255408-aaaaaaaaaahhhhhhhhh-help/ Share on other sites More sharing options...
xProteuSx Posted January 20, 2012 Author Share Posted January 20, 2012 Found an answer on the internet. Have to change filed to: field = document.markform['marked[]']; Link to comment https://forums.phpfreaks.com/topic/255408-aaaaaaaaaahhhhhhhhh-help/#findComment-1309500 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.