|
-
Sep 7th, 2004, 11:40 AM
#1
Thread Starter
Fanatic Member
using setTimeout
hi there,
The following script is for moving an object(a textbox).but it does not move
help me fixing the problem please.And is it possible to display
"setTimeout value" as the script is running...!!
thanks a lot
*********************************
<SCRIPT LANGUAGE="javascript">
function runrace()
{
document.bgColor="red";
document.fn.text1.style.left = document.fn.text1.style.left+=50;
setTimeout("runrace()", 100);
}
</script>
<form name=fn>
<input type=button value="start" onclick="runrace()"><br>
<INPUT TYPE=TEXT NAME="text1" SIZE="3">
</form>
Last edited by merhaba; Sep 7th, 2004 at 11:43 AM.
-
Sep 7th, 2004, 01:59 PM
#2
Frenzied Member
there might also be something else but change "+=50" to "+50"
Have I helped you? Please Rate my posts. 
-
Sep 7th, 2004, 04:53 PM
#3
style.left is often a string containing both value and unit. At least, it should be. As a result, +50 will append "50" to this string, leading to an invalid property value and thus no change.
You have to parse the integer part out of style.left, hope that the unit is px, add your integer to the integer part and write the result out again.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 8th, 2004, 08:45 AM
#4
This kinda works. I didn't learn Javascript for long, so I don't know how to convert a string to a number. Try playing around with this:
Code:
<html>
<head>
<title>
Test
</title>
<script language="javascript">
var lastval = 0;
function runrace()
{
var str = document.forms[0].elements[1].style.left;
var start = str.indexOf("px");
var val = str.substr(0, start);
//alert(val);
document.bgColor="red";
lastval = val + 5;
document.forms[0].elements[1].style.left = lastval;
val = lastval
alert('val now equals: ' + val);
//alert(document.forms[0].elements[1].style.left+50);
setTimeout("runrace()", 1000);
}
</script>
</head>
<body>
<style type="text/css">
.bla
{
cursor:hand;
left: 500;
}
</style>
<form name=fn>
<input type=button value="start" onclick="runrace()"><br>
<INPUT TYPE=TEXT NAME="text1" SIZE="3" style="position:absolute;">
</form>
</body>
</html>
Phreak
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Sep 8th, 2004, 09:32 AM
#5
Frenzied Member
you can use parseInt() to get the numbers. For instance:
Code:
var a = "123"
alert(a+1) //returns 1231
alert(parseInt(a)+1) //return 124
var b= "150px"
alert(b) //returns 150px
alert(parseInt(b)) //returns 150
alert(b+1) //returns 150px1
alert(parseInt(b)+1) //returns 151
Have I helped you? Please Rate my posts. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|