Click to See Complete Forum and Search --> : weird style error


MarkNL
04-25-2003, 10:00 AM
I have made this code to move an image:

--------------------
<script>
function move(dif)
{
map.style.left = map.style.left + dif;
}
</script>

<a onclick="move(10);"><img src="left.gif"></a>
<a onclick="move(-10);"><img src="right.gif"></a>
<img name="map" src="image.gif" style="position:absolute">
-------------------

But it only works the first time you click right or left, and after that it gives a javascript error.
How could i fix this?

AdamBrill
04-25-2003, 10:19 AM
Try this instead:<script language=javascript type="text/javascript">
function move(dif)
{
map.style.left = parseInt(map.style.left) + dif;
}
</script>

<a onclick="move(10);"><img src="left.gif"></a>
<a onclick="move(-10);"><img src="right.gif"></a>
<img name="map" src="image.gif" style="position:absolute; left:100px;">

MarkNL
04-25-2003, 11:22 AM
Thx for that code, it works fine :)