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 Link to comment https://forums.phpfreaks.com/topic/58122-solved-javascript-conflict-with-object-name-itmchk/ 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. Link to comment https://forums.phpfreaks.com/topic/58122-solved-javascript-conflict-with-object-name-itmchk/#findComment-289100 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. Link to comment https://forums.phpfreaks.com/topic/58122-solved-javascript-conflict-with-object-name-itmchk/#findComment-289104 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.