Question : IE 7 throws "invalid argument" jscript error when change "top" css property

Trying to change the top position of an element... if I pass in the value as a variable like this:
parent.document.getElementById(id).style.top  = newLocation + "px";
I get an "invalid argument" error in javascript.

However, if I manually put in a value like this:
parent.document.getElementById(id).style.top  = "200px";
It passes.

Full code of my function below.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
function nudge(id,top,left) {
	
	if(top != "") {
		curLocation = parseInt(parent.document.getElementById(id).style.top);
		newLocation = parseInt(curLocation) + parseInt(top);
		parent.document.getElementById(id).style.top  = newLocation + "px";
	}
	
	if(left != "") {
		curLocation = parseInt(parent.document.getElementById(id).style.left);
		newLocation = parseInt(curLocation) + parseInt(left);
		parent.document.getElementById(id).style.left  = newLocation + "px";
	}
}
Open in New Window Select All

Answer : IE 7 throws "invalid argument" jscript error when change "top" css property

Hi susanBuck,

probably your newLocation not is a valid number, to debug it show the newLocation (e.g. document.title = newLocation). Probably you have a NaN value.

Regards.
Random Solutions  
 
programming4us programming4us