SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Something weird

  1. #1
    SitePoint Zealot bensheard's Avatar
    Join Date
    Jun 2006
    Location
    Cape Town | South Africa
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face Something weird

    Hi

    I dont know why this is happening, but maybe it is supposed to happen. I have a checkbox on a page that when checked, checks all the others on that page, using getElementByTagName("input") and then checking it if the type attribute is checkbox. (tell me if you want me to post the code) This works perfectly normally, but as soon as I put a form field around it (which is neccesary) it says Object doesn't support this property or method. I have used the onclick attribute of the checkbox to execute the script, if that has something to do with it.

    Thanks
    Ben Sheard
    -------------
    Log all your dives easily and quickly from anywhere in the world
    www.divinglogs.cafe150.com

  2. #2
    SitePoint Member dplumlee's Avatar
    Join Date
    Sep 2006
    Location
    Indiana
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would need to see the code!

  3. #3
    SitePoint Zealot bensheard's Avatar
    Join Date
    Jun 2006
    Location
    Cape Town | South Africa
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi
    Here is the code:
    Code:
    <body>
    <form action = "something.php" method="post" name="f">
    <input type="checkbox" name="checkall" value="1" onclick="checkall(this)"><br><br> 
    <input type="checkbox" name="check1" id="check1" value="1"><br> 
    <input type="checkbox" name="check2" id="check2" value="1"><br> 
    <input type="checkbox" name="check3" id="check3" value="1"><br> 
    <input type="checkbox" name="check4" id="check4" value="1"><br> 
    <input type="checkbox" name="check5" id="check5" value="1"><br>
    </form>
    </body>
    
    and this is the javascript:
    Code:
    function checkall(id){
    var inputs = document.getElementsByTagName('input'); 
    for (var i = 0; i < inputs.length; i++) 
    	{ 
    	if (inputs[i].getAttribute('type') == 'checkbox') 
    	 {
    	 if (id.getAttribute('checked') == "")
    		{
    		inputs[i].setAttribute('checked', '');
    		}
    	 else
    		{
    		inputs[i].setAttribute('checked', 'checked');
    		}
    	 }
    	}
    }
    
    Ben Sheard
    -------------
    Log all your dives easily and quickly from anywhere in the world
    www.divinglogs.cafe150.com

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The name of your function is the same as the name attribute of the checkbox

  5. #5
    SitePoint Zealot bensheard's Avatar
    Join Date
    Jun 2006
    Location
    Cape Town | South Africa
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!!!!! It has been bugging me for days... it is finally working!!!
    Ben Sheard
    -------------
    Log all your dives easily and quickly from anywhere in the world
    www.divinglogs.cafe150.com


Bookmarks

Posting Permissions

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