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 7 of 7
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    issue with my code...cant work out error

    Hi all,
    i get an error when i try to run this function, on line 18, column 20...

    Code:
    function initDisp(list, img) {
    
    	var rtnCookie = getCookie(list);
    
    
           //var lstStyle = document.getElementById("cal_div").style;
    
                    if (rtnCookie=="true"){
                       document.getElementById(list).style.display="block";
          		   document.getElementById(img).src = "arrow_up.gif";	
    	   
                    }
                    else {
    		   document.getElementById(img).src = "arrow_down.gif";
                       document.getElementById("cal_div").style.display.display="none";
                     }
    
    }
    line 18, column 20 refers to this line...

    Code:
    document.getElementById(list).style.display="block";
    and this is the erro message i get./... is 'Object Required'...

    this is the code i try n run to call the function...
    Code:
    <script type="text/javascript">initDisp('cal_div','cal_img');</script>
    and both cal_div and cal_img are correct, as they work in a seperate function...

    does anyone know why this could be happening??

    Thnks all in advance, Justin

  • #2
    Regular Coder
    Join Date
    Aug 2005
    Posts
    282
    Thanks
    0
    Thanked 0 Times in 0 Posts
    are you sure that was the right line?
    for this is really disturbing code:
    Code:
    document.getElementById("cal_div").style.display.display="none";

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by KC-Luck
    are you sure that was the right line?
    for this is really disturbing code:
    Code:
    document.getElementById("cal_div").style.display.display="none";
    lol, that would be a copy n paste type. but i just had a thought....

    my javascript is calling the function before the div tag has loaded the page...

    so i have put my script to change the div under the loading of my div tag...

    and this is now my function...

    Code:
    function initDisp(list, img) {
    
    	var rtnCookie = getCookie(list);
        var lstStyle = document.getElementById(list).style;
    
        if (rtnCookie=="true"){
        lstStyle.display="block";
        document.getElementById(img).src = "arrow_up.gif";	
    	}
        else {
    	document.getElementById(img).src = "arrow_down.gif";
        lstStyle.display="none";
        }
    
    }
    and im now getting errors on this line:
    Code:
    var lstStyle = document.getElementById(list).style;
    Last edited by jussa; 03-07-2006 at 04:25 AM.

  • #4
    Regular Coder
    Join Date
    Aug 2005
    Posts
    282
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It would help to see the whole page, instead of just take guesses on how the whole page is interacting w/ this small segment of code

  • #5
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    Actually, I'm pretty sure the only error you could get on that line is a null reference error.

    And that would come from document.getElementById(list) not returning an object.

    And that would come from the ID your passing in not existing in your document.

    Check the value of list.

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,038
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Run the page in Firefox and check the Javascript Console to see more meaningful error messages and line numbers.

  • #7
    Regular Coder
    Join Date
    Mar 2006
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i worked it out...it was the fact that i was trying to parse the list value, without the <div id""> been loaded yet. sorry guys thanks for all the help tho


  •  

    Posting Permissions

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