Welcome to WebmasterWorld Guest from 54.147.63.124

Forum Moderators: open

Message Too Old, No Replies

document.getElementById is null error

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

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

New User

5+ Year Member

joined:Aug 6, 2009
posts:17
votes: 0


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?

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

Junior Member

10+ Year Member

joined:Dec 7, 2004
posts:130
votes: 0


The element isn't found in the DOM.

HTH, Tom

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

Senior Member

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

joined:Dec 9, 2003
posts:3416
votes: 0


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.
2:41 pm on Aug 12, 2009 (gmt 0)

New User

5+ Year Member

joined:Aug 6, 2009
posts: 17
votes: 0


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]

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

New User

5+ Year Member

joined:Aug 6, 2009
posts:17
votes: 0


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.
3:06 pm on Aug 12, 2009 (gmt 0)

Senior Member

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

joined:Dec 9, 2003
posts:3416
votes: 0


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])
4:49 am on Aug 13, 2009 (gmt 0)

New User

5+ Year Member

joined:Aug 6, 2009
posts:17
votes: 0


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.

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

Senior Member

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

joined:Dec 9, 2003
posts:3416
votes: 0


Glad you got it sorted out. :)
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members