...

View Full Version : issue with my code...cant work out error



jussa
03-07-2006, 03:41 AM
Hi all,
i get an error when i try to run this function, on line 18, column 20...


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...


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...

<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

KC-Luck
03-07-2006, 04:17 AM
are you sure that was the right line?
for this is really disturbing code:

document.getElementById("cal_div").style.display.display="none";

jussa
03-07-2006, 04:20 AM
are you sure that was the right line?
for this is really disturbing 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...


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:
var lstStyle = document.getElementById(list).style;

KC-Luck
03-07-2006, 05:58 AM
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 ;)

Beagle
03-07-2006, 08:29 PM
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.

glenngv
03-08-2006, 02:02 AM
Run the page in Firefox and check the Javascript Console to see more meaningful error messages and line numbers.

jussa
03-08-2006, 02:21 AM
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 :o thanks for all the help tho



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum