Image src

Trying to figure out where i’m going wrong here…

function incdot(fname,val) {
   var newval = parseInt(document.getElementById(fname).value) + val;
   var imgname = fname + "img";
  if(newval <= 5 && newval >= 0) {
     document.getElementsByName(imgname).src = fdot[newval].src;
	 document.getElementsByName(fname).value = newval;
  }
}

In IE, newval gets set correctly. fdot[newval].src correctly returns a string.
The image source doesnt change. No errors are thrown by IE’s debugger
Chrome’s debugger and FF’s error console decides that document.getElementById(fname) is null, and fails immediately.

getElementsByName() returns an array of objects.

Which index in that array are you assigning fdot[newval].src to the object’s src?

okay… that makes sense… was just tripping me up because there was only one such element…

but why does FF and Chrome think document.getElementById(fname) is null?

ok, you need to do some basic debugging.

Just above

 
   [COLOR=#003366][B]var[/B][/COLOR] newval = parseInt[COLOR=#66cc66]([/COLOR]document.[COLOR=#006600]getElementById[/COLOR][COLOR=#66cc66]([/COLOR]fname[COLOR=#66cc66])[/COLOR].[COLOR=#006600]value[/COLOR][COLOR=#66cc66])[/COLOR] + val;
 

insert

 
alert(fname);

then make sure you have an element in your html with an id equal to the output of the alert().

I suspect you won’t have and that is why FF and Chrome are tripping up. I think some browsers will take the value of the name attribute as the id if the id attribute does not exist.

I can’t find the thread where I thought I read that some browsers use the element name as the id where the id is missing. Maybe I was wrong.

Anyway, I assume the debugging I suggested has helped you fix your problem by now.