Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Select All Checkboxes!!? help!

    Hello,

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

    Code:
    <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:

    Code:
    <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:

    Code:
    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,

    ~Chud37

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,391
    Thanks
    11
    Thanked 565 Times in 558 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •