Click to See Complete Forum and Search --> : Simple Timer
thejoker101
12-27-2002, 10:05 AM
Ok, I have a javascript that sets text. When a link is moused over, it changes the text. when the link is moused out, the text changes again. I want there to be a delay in the time the text is changed after the mouse out. I figured I'd just do a set timeout and then call the function. Problem is setTimeout runs the function and then does the timeout. I'm sure there is a simple workaround to this. I'm just not very fluent in javascript to know. Any help?
Charles
12-27-2002, 10:27 AM
It sounds like you are using Window.prototype.setTimeout() incorrectly. See http://developer.netscape.com/docs/manuals/js/client/jsref/window.htm#1203758 for details. It also sounds like you're making a page that relies upon JavaScript. This is a bad thing for it will fall flat on its face more than one out of every ten times. Many people do not use JavaScript (http://www.thecounter.com/stats/2002/November/javas.php) and some cannot use a mouse. No mouse means no onmouseover.
AdamBrill
12-27-2002, 10:31 AM
Try this:
onmouseover="javascript:setTimeout('TheFunction()',1000)"
Just change the function name and the length of time to wait and your ready to go.
thejoker101
12-27-2002, 10:35 AM
To Charles -
No, I am not "relying" on javascript here, it is just and added thing, that, if it doesn't work at all, takes nothing away from the site. and yes, I do know how to use the setTimeout function.
To AdamBrill -
Won't that run the script and then do the timeout. I need it the other way around.
Originally posted by thejoker101
Won't that run the script and then do the timeout. I need it the other way around.
No, it will run the function after it has waited for one second.
hi AdamBrill,
how can i use the code and i dont know the java script
roby
Charles
12-27-2002, 11:33 AM
Won't that run the script and then do the timeout[?]It would appear that you don't know how to use the setTimeout method of a Window object. From http://developer.netscape.com/docs/manuals/js/client/jsref/window.htm#1203758
Syntax
setTimeout(expression, msec)
setTimeout(function, msec[, arg1[, ..., argN]])
Parameters
expression
A string containing a JavaScript expression. The expression must be quoted; otherwise, setTimeout calls it immediately. For example, setTimeout("calcnum(3, 2)", 25).
msec
A numeric value or numeric string, in millisecond units.
function
Any function.
arg1, ..., argN
The arguments, if any, passed to function.
roby-
It depends what you want to do with it. You could use it like this:
<html>
<head>
<script language="JavaScript">
function test(){
alert('test');
}
</script>
</head>
<body>
<a href="#" onClick="javascript:setTimeout('test()',2000)">Alert Me</a>
</body>
</html>
What this will do is wait 2 seconds after you click the link to popup the alert.
hi,
i want it appear in the home page of my site and the code that you write it befor is does't work i don't know why.
roby
The code I wrote works fine. I don't know why it doesn't work for you. Did you copy it out exactly as I have it typed down?
What do you want it to do on your site after it waits??
Charles
12-27-2002, 03:31 PM
Originally posted by pyro
The code I wrote works fine. I don't know why it doesn't work for you. Did you copy it out exactly as I have it typed down?
What do you want it to do on your site after it waits?? Though, strictly speaking that snippet of mark up is incorrect. The value of the ONMOUSEOVER attribute is supposed to be some script. The "javascript" pseudo-scheme does not belong here. It doesn't belong as a part of the value of the HREF attribute either, but that's not so bad. In the former case most browsers simply ignore your error. The later case is simply a non-standard but widely implemented extension. Also, if you don't return false from your event handler then the browser should take the user to the top of the page. Instead use:
<a href="#" onmouseover="setTimeout('alert("foo")', 2000); return false">foo</a>
But that will leave you with a link to nowhere one out ten times. If you are not going to use the HREF attribute to send JavaScript free users to a better page then use JavaScript to hide the link when it will not function:
document.write('<a href="#">foo</a>');
document.links[document.links.length-1].onmouseover = function() {setTimeout('alert("foo")', 2000); return false};
hi,
just i want to know and use the timmer that you taken about it
roby