Web Analytics Made Easy -
StatCounter Select All Checkboxes!!? help! - CodingForum


No announcement yet.

Select All Checkboxes!!? help!

  • Filter
  • Time
  • Show
Clear All
new posts

  • Select All Checkboxes!!? help!


    I have a form generated by mySQL and PHP, and inside the form (named 'UpdateDB') each line has checkboxes, like so:

    <input type="checkbox" name="checkbox[]" value="96" onclick="highlight(this,'check_96')">
    The onclick is to highlight the row, that works fine. However, I wrote a javascript function that toggles the select all the checkboxes or none. This is done by an image:

    <img src="img/select.png" align="top">
    <a href="#" onClick="togBox('updateDB');"><img src="img/all.png" name="listToggle" align="top"></a>
    Easy, right? So heres the Javascript function that the above image (the 'none' part) links to:

    function togBox(form) 
    	{	var myForm = document.forms[form];
    		document.listToggle.src=='http://gospeltruth.tv/admin/img/all.png' ? toggle = true : toggle = false;
    		(toggle) ? document.listToggle.src='img/none.png' : document.listToggle.src='img/all.png';
    		for( var i=0; i < myForm.length; i++ ) 
    			(toggle) ? myForm.elements[i].checked = 'checked' : myForm.elements[i].checked = '';
    Its a brilliant function if I do say so myself, and this is what I dont get: two days ago, it was working fine, today, its not working at all. The image changes, but IE flags up the 'myForm.length' as an error.

    How was it working 2 days ago and not today, when I havent touched it? Can anybody advise why its not currently working?

    Thanks for your help,


  • #2
    I think it's supposed to be myForm.elements.length ... myForm is just a single form element which doesn't "have" a length. But its elements collection has a length and you use the index "i" to access a specific element using myForm.elements[i] anyway.