SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Object required

  1. #1
    SitePoint Addict I don`t mind's Avatar
    Join Date
    Feb 2006
    Location
    LA
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Object required

    Hello there,

    first my code:

    Code:
    function show_hide (id) {
    	for (i = 1;i<=25;i++) {
    		if (i == id) {
    			if (document.getElementById(id).style.visibility == "hidden") {
    				document.getElementById(id).style.visibility = "visible";
    				document.getElementById(id).style.overflow = "visible";
    				document.getElementById(id).style.height = "100%";
    				document.getElementById(id).style.width = "100%";
    			} else {
    				document.getElementById(id).style.visibility = "hidden";
    				document.getElementById(id).style.overflow = "hidden";
    				document.getElementById(id).style.height = "1px";
    				document.getElementById(id).style.width = "1px";
    			}
    		} else {
    			
    			document.getElementById(i).style.visibility = "hidden";
    			document.getElementById(i).style.overflow = "hidden";
    			document.getElementById(i).style.height = "1px";
    			document.getElementById(i).style.width = "1px";
    			
    		}		
    	}
    }


    My problem is that I am getting a javascript error which says ‘Object required’ and to be honest I am not sure what the problem is ….
    Words are weapons of Mass Destruction.

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm guessing that at some point one of your "document.getElementById"s is not finding the object with that Id.

    Why are you looping 25 times?

    In your else statement starting on line 16, it is going to be searching for elements with numbers as IDs - 1) ids shouldn't start with numbers AFAIK, and 2) do you have 25 elements with Ids ranging from "1" to "25"?

  3. #3
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use Firefox for debugging, IE errors are just confusing.

  4. #4
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


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
  •