Welcome to WebmasterWorld Guest from 54.196.224.166

Forum Moderators: open

Message Too Old, No Replies

document.getElementById is null error

document.getElementById(c + arguments[i]) is null

     

BungeeJumper

9:36 am on Aug 12, 2009 (gmt 0)

5+ Year Member



I'm having problems figuring out the cause of this error message -

document.getElementById(c + arguments[i]) is null

Is it saying that it can't find the element "to get" because c+arguments[i] is null?

or is it saying it can't put a value in that location because I didn't give it one?

Arno_Adams

10:47 am on Aug 12, 2009 (gmt 0)

10+ Year Member



The element isn't found in the DOM.

HTH, Tom

whoisgregg

2:07 pm on Aug 12, 2009 (gmt 0)

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member



What is contained in the variables "c" and "arguments[i]?" You may try putting in an alert right before the document.getElementById() call to see what is being sent to it.

BungeeJumper

2:41 pm on Aug 12, 2009 (gmt 0)

5+ Year Member



I can't find it. Here is what the elements look like in the source code (either a c or a sc appended to their category id number)

<font id="c2719">21</font>)</small></i><i><small>(<font id="sc2719">37</font>

and here is the function I'm using to do that. Note I said "do" because it does update both "c##" and "sc##" but throws the error messages too.

function changeText2(){
var arrlength = arguments.length/3;//ex. 60/3 =20
var arrstartsc = arrlength+arrlength;//ex.40
var arrstartc = arrlength;//ex. 20
var c = "c";
var sc = "sc";
for( var i = 1; i < arrlength; i++ ) {////ex.20

document.getElementById(c+arguments[i]).innerHTML = arguments[arrlength+i];
document.getElementById(sc+arguments[i]).innerHTML = arguments[arrstartsc+i];

}
}

and here is the call to that function from inside an AJAX operation...

onmouseover=\"........ changeText2(".$cat_group_string.",".$cat_group_pops_string.",".$cat_sub_group_pops_string.")

and just before that function call I can echo the three variables in it as these

$cat_group_string 1 = 99,2807,2682,70,96,94,101,82,83,2717,72,100,77,95,80,84,81,93,98,71
count 2 = 20
cat_group_pops_string 2 = 0,0,0,0,0,10,0,1,0,0,0,0,0,0,1,0,0,0,0,0
count 3 = 20
cat_sub_group_pops_string 3 = 0,0,0,0,0,19,0,1,0,0,0,0,0,0,1,0,0,0,0,0

[edited by: eelixduppy at 12:32 am (utc) on Aug. 13, 2009]
[edit reason] disabled smileys [/edit]

BungeeJumper

2:47 pm on Aug 12, 2009 (gmt 0)

5+ Year Member



Duhhh, I was reviewing the post afterward and the problem jumped out at me. I found the error. Sorry for the false alarm and thanks.

whoisgregg

3:06 pm on Aug 12, 2009 (gmt 0)

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member



What jumped out at me is that the "c" was being interpreted as a variable instead of a string. Was the solution something like this?

 document.getElementById('c' + arguments[i])

BungeeJumper

4:49 am on Aug 13, 2009 (gmt 0)

5+ Year Member



No, it was something more inept than that. It c+arguments[i] is referencing the ids on the current page. I was in the middle of coding it to move on to the next page and the code was pulling the id numbers of the next page of subcategories, not the present one. I noticed the id numbers weren't the ones displayed on the page,

I had first tried getting the "c" attached by making it a string but couldn't get it to work so I made a variable "c" to hold the string "c"., It worked.

Thanks all.

whoisgregg

3:18 pm on Aug 13, 2009 (gmt 0)

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Glad you got it sorted out. :)