Jump to content

Recommended Posts

hey , i got 2 function , the one working and the other one isn't

 

here's the functions :

 

                        var toDisplay = "f";
		function human(){
			var toAdd = toDisplay.substring(0,1);
			setTimeout(human , 500);
			document.getElementById('box').innerHTML += toAdd;
		}
		human(); // works (display "f" every half a sec)

		function human2(toDisplay2){
			var toAdd = toDisplay2.substring(0,1);
			var t = setTimeout("human2(toDisplay2)" , 500);
			document.getElementById('box').innerHTML += toAdd;
		}
		human2("dsd"); // not working (only display "d" and stop)

 

the first function works ( keep printing "f" every 0.5 sec )

the second function only work once and than stop ( print "d" and than stop )

 

what's the problem with the second function?

 

thanks , Mor.

Link to comment
https://forums.phpfreaks.com/topic/246670-noob-question-what-the-difference/
Share on other sites

If it is running once then failing it is the timeout which is failing. I would think it is because you are trying to send a vaiable through the timeout but still have it enclosed in " hence making it part of the string. Try this:

 

setTimeout("human2(" + toDisplay2 + ")" , 500);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.