D
DJ Craig
I'm new to JavaScript. I have a checkbox with a text field next to it.
When the checkbox is checked, I want the page to automatically refresh
with a time interval. The time interval will be equal to the number
entered in the text box (in milliseconds). When I run this code, it
always crashes the browser (so I'm assuming that it's trying to refresh
the page with no time delay). What's wrong with this code?
<html>
<head>
<script type="text/javascript">
var loc = location;
var delaytime = 5000;
while(delaytime>=500)
setTimeout("location=loc;",delaytime);
</script>
</head>
<body>
<script type="text/javascript">
function togglerefresh(checked){
if(checked)
delaytime = 0;
else
delaytime = getElementById('delay').value;
}
</script>
<form action="index.php" method="post">
<input type="checkbox" onclick="ref=true;"
onchange="togglerefresh(this.value);" title="Refresh automatically" />
<input type="text" value="5000" name="delay"
onblur="delaytime=this.value;" size="6" maxlength="6" title="Delay
between refreshes" /> milliseconds
</form>
</body>
</html>
When the checkbox is checked, I want the page to automatically refresh
with a time interval. The time interval will be equal to the number
entered in the text box (in milliseconds). When I run this code, it
always crashes the browser (so I'm assuming that it's trying to refresh
the page with no time delay). What's wrong with this code?
<html>
<head>
<script type="text/javascript">
var loc = location;
var delaytime = 5000;
while(delaytime>=500)
setTimeout("location=loc;",delaytime);
</script>
</head>
<body>
<script type="text/javascript">
function togglerefresh(checked){
if(checked)
delaytime = 0;
else
delaytime = getElementById('delay').value;
}
</script>
<form action="index.php" method="post">
<input type="checkbox" onclick="ref=true;"
onchange="togglerefresh(this.value);" title="Refresh automatically" />
<input type="text" value="5000" name="delay"
onblur="delaytime=this.value;" size="6" maxlength="6" title="Delay
between refreshes" /> milliseconds
</form>
</body>
</html>