Dragen Posted July 2, 2007 Share Posted July 2, 2007 Hi, I'm not too brilliant with javascript, as I mainly codse in php.. leaving javascript alone if I can. I've got a series of checkboxes, all named 'itmchk[]' The [] is so that my php code will read it as an array. Now I'm using javascript so when I select one checkbox it checks them all. function checkAll(checkname, exby) { for (i = 0; i < checkname.length; i++) checkname[i].checked = exby.checked? true:false } Then the checkbox to check the others looks like this: <input type="checkbox" onclick="checkAll(document.editlist.itmchk[],this);" /> Now my problem is javascript seems to get a conflict from the [] in the check name. If I remove it from the checkboxes it will work fine, but I need it there for my php array. Is there any way to stop javascript conflicting with []? Thanks Quote Link to comment Share on other sites More sharing options...
arianhojat Posted July 3, 2007 Share Posted July 3, 2007 Javascript wont know how to parse that... Try this (assuming editlist is name of form?) document.editlist['itmchk[]'] or document.forms[0].elements['itmchk[]'] or document.forms[0]['itmchk[]'] or document.forms['editlist']['itmchk[]'] one of those WILL work. Quote Link to comment Share on other sites More sharing options...
Dragen Posted July 3, 2007 Author Share Posted July 3, 2007 thanks. I've actually found a way round it which seems to work: function ckeck_uncheck_all() { var frm = document.editlist; for (var i=0; i < frm.elements.length; i++) { var elmnt = frm.elements[i]; if (elmnt.type == 'checkbox') { if(frm.checkall.checked == true){ elmnt.checked=false; } else{ elmnt.checked=true; } } } if(frm.checkall.checked == true){ frm.checkall.checked = false; } else{ frm.checkall.checked = true; } } then the checbox has this code: <input name="checkall" type="checkbox" class="checkbox" onclick="ckeck_uncheck_all();" /> which seems to check and uncheck every checkbox in the named form. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.