Jump to content

setTimeout


ApocalypeX

Recommended Posts

I've literally spent 4 hours rewriting this code every possible way. It still doesn't work. My error console says "delayTran is undefined".Help please; I'll write you a cookie from my heart.

<html>	<head>		<title>Code effect</title>		<link rel="stylesheet" type="text/css" href="CSS/main.css">		<script type="text/javascript" src="JS/binary.js"></script>		<script>			var i = 0;			var t;			function trans(id){				var ele = document.getElementById(id);				var strLenCheck = ele.innerHTML.length / 8;				function delayTran(){					ele.innerHTML = ele.innerHTML.replace(ele.innerHTML.substr(i,i+8), doasc(ele.innerHTML.substr(i,i+8)));					alert(i)					i++;				}				while(i < strLenCheck){					t=setTimeout("delayTran()",3000);				}			}		</script>	</head>	<body>		<div id="code" onclick="trans('code')">0100100001100101</div>	</body></html>

This code uses other functions like doasc which is defined in the binar.js.

Link to comment
Share on other sites

setTimeout runs in the window scope. If you give it a string of code, it runs that under window. So it's looking for window.delayTran. But you didn't define delayTran in the window (global) scope, you defined it in the trans function. You can either give a reference to the function instead of a string to run:t=setTimeout(delayTran,3000);or you can define it in the window scope:window.delayTran = function(){

Link to comment
Share on other sites

setTimeout runs in the window scope. If you give it a string of code, it runs that under window. So it's looking for window.delayTran. But you didn't define delayTran in the window (global) scope, you defined it in the trans function. You can either give a reference to the function instead of a string to run:t=setTimeout(delayTran,3000);or you can define it in the window scope:window.delayTran = function(){
Ahhh! Thank you that makes sense. It works :) If anyone is interested its a jquery effect I'm working on. I might post it up in the critique later.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...