homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

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

 9:36 am on Aug 12, 2009 (gmt 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)

The element isn't found in the DOM.

HTH, Tom


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

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)

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)

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)

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)

Glad you got it sorted out. :)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved