Forum Moderators: open

Message Too Old, No Replies

setInterval not working

         

MattCoatney

11:01 pm on Nov 5, 2004 (gmt 0)

10+ Year Member



Im rather new to javascript so im not sure what youll need to know to help me on this. Id rather err on the side of extraneousness.

Im running aspx pages through IIS 6
using IE for testing

Ive got a problem that I wanted to use javascript to solve. But I hit a snag with setInterval. I cant get the darn thing to work the way its supposed to. Here is a sample:

<code>
<html>
<head>
<script language="JavaScript" type='text/javascript'>
t=setInterval('clock()',100);
function clock()
{
document.write( "¦" );
}

</script>
</head>

<body>
</body>
</html>

</code>
This will print ¦ one time. I was under the impression that setInterval will automatically continue to call the function I specified every 100 miliseconds...

if so, what is interfering with this?

StupidScript

11:37 pm on Nov 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The "document.write()" instruction, a one-time event.

Try using a form element to display the visual:

<form id="timer">
<input type="text" id="display" size=100 style="border-width:0px;font-weight:bold">
</form>
<script type="text/javascript">
t=setInterval("clock()",100);
var ticks = "¦";
var tickDisplay = document.getElementById("display");
function clock() {
tickDisplay.value += ticks;
}
</script>

<edit>Welcome to the forums, Matt!</edit>

StupidScript

4:46 am on Nov 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just to tidy up the initialization of everything ...

<form id="timer">
<input type="text" id="display" size=100 style="border-width:0px;font-weight:bold">
</form>
<script type="text/javascript">
var ticks = "¦";
var tickDisplay = document.getElementById("display");
function clock() {
tickDisplay.value += ticks;
}
t=setInterval("clock()",100);
</script>

Sorry ... :)

MattCoatney

10:02 pm on Nov 8, 2004 (gmt 0)

10+ Year Member



Thanks but I cant use a form. I want to use this to solve a problem Im having in ASP.Net but ASP.NET requires there to be only one form.

StupidScript

3:46 am on Nov 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



innerHTML, then? :)

Bernard Marx

8:54 am on Nov 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Keep the code, just lose the form.
You don't need to use a form to be able to use form elements. It's only necessary when the resulting input is to be posted.

adni18

1:09 pm on Nov 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For example, you could use a <span> tag or a <div> tag.

StupidScript

2:10 am on Nov 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Of course, you're right ... <sigh>

How old am I? :)