Click to See Complete Forum and Search --> : parseInt()
daub815
04-11-2003, 02:43 PM
I need to be able to read the number of pixels an object is away from the margin. Should this work:
var test = document.getElemtentById('theObject').style.left;
alert(test);
Let's say that theObject is 20px from the margin. Shouldn't return 20 not NaN.
Thanks in advance!
viravan
04-11-2003, 03:16 PM
I suspect that if you do this:
alert(document.getElemtentById('theObject').style.left);
you'll get a string with the following value:
20px
If so, why don't you try to parse the result by ignoring the the trailing px and you will not get the NaN.
:)
V.V.
daub815
04-13-2003, 05:34 PM
I have tried everything with this parseInt(). I am thinking the reason it does not work is because I am trying to read the style.left from a inline element. So I am also guessing you can only get pixel positions from absolute elements. Is this correct?
gil davis
04-13-2003, 05:43 PM
Perhaps you could be a bit more precise, like posting some code.
BTW, alert() is a very handy function for debugging and finding out on your own what the problem might be.
daub815
04-13-2003, 05:49 PM
whenever I put an alert it appears blank. I am trying to get around doing a lot of browser sniffing. I need to get the number of pixels a table is away from the left margin. I tried the parseInt() but I get an error. Here is what I got:
daBody = document.getElementById('theTable');
var start = (parseInt(daBody.style.left) - 25) + "px";
start appears as 0. Is this code correct?
Thanks for responding.