Click to See Complete Forum and Search --> : Subtracting value


florida
10-20-2003, 10:55 AM
How do you subtract something in JavaScript data?
I have a y coordinate (this.y) where I need to subtract 25 from the its value only in IE.

if (!netscape4)
{
layerHeader = '<div id=myView' + this.myText + ' style="background: ; width: ' + this.width + '; visibility: hidden; position: absolute; left: ' + this.x + '; top: ' + this.y + ';">';
}
else
{
layerHeader = '<layer id=myView' + this.ID +'visibility=hide left=' + this.x +' top =' + this.y + '>';
}


I tried this:
layerHeader = '<layer id=myView' + this.ID +' visibility=hide left=' + this.x +' top =' + this.y - 25 + '>';
And it doesnt work and gives a JavaScript error.
Please advise.

Jeff Mott
10-20-2003, 11:24 AM
Since the + and - operators have the same precedence they are evaluated left to right. So this.y is concatenated to the string, and then you try to subtract 25 from the string (error). So all you need to do is parenthesize (this.y - 25)

florida
10-20-2003, 11:46 AM
Thanks