I thought I had found just what I was looking for when

This is a discussion on "I thought I had found just what I was looking for when" within the JavaScript Forum section. This forum, and the thread "I thought I had found just what I was looking for when are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Oct 4th, 2005, 08:02
Junior Member
Join Date: Jul 2005
Location: Centennial CO USA
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
I thought I had found just what I was looking for when

I have been trying to find a a JavaScript function that will repeatedly run my change image function and when I found a site that gave it to me I thought I had the answer. My own writing of a recursive function kept failing so the comments in code below seemed like the answer I was looking for. However I think I've been following the instructions faithfully but it doesn't work. Below is a quote in a code snippet which can be found at this link http://songhaysystem.com/document.ph...&code=htmlscrp. It is followed by my experimental use of this code snippet which should write the numbers 1 through 10 one line at a time. Firefox will only render the number 1 from my code. The Firefox JavaScript console gives me the following error messages in warnings.

"Warning: assignment to undeclared variable timeoutID
Source File: file:///c:/htmlplay2/pro1LeadImage/whyIwasLookingFor.htm
Line: 15"

Also this error message.

"Error: MyFunc is not defined
Source File: file:///c:/htmlplay2/pro1LeadImage/whyIwasLookingFor.htm
Line: 15"

I would appreciate it very much if somebody could help me get this code going. Below is all that I have mentioned above.

" Many designs using a for or while loop structure may instead have needed the setTimeout() method of the window object calling a function recursively. The general form of this structure is:

function MyFunc() {
//code here
timeoutID = setTimeout("MyFunc()", 1000)
}

where timeoutID is a script-global variable. After MyFunc() is called, this structure then recursively calls MyFunc() every second until clearTimeout(timeoutID) is used. Unlike a for or while loop, this "loop" is time based."


My code.


<head>
<title></title>
<script language="JavaScript">
<!--
var c=0;
var timeoutID=0;
function MyFunc() {
c += 1;
window.document.write(c + "</br>");
timeoutID = setTimeout("MyFunc()", 1000);
}
-->
</script>
</head>

<body onload="MyFunc()">

</body>

</html>
Reply With Quote

  #2 (permalink)  
Old Oct 4th, 2005, 09:17
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
The problem comes when writing to the document stream directly... this however will work if you do it a slightly different way:
Code: Select all
<head> 
<title></title> 
<script language="JavaScript"> 
<!-- 
var c=0; 
var timeoutID=0; 
function MyFunc() { 
c += 1;

myDiv = document.getElementById("message");
myDiv.innerHTML = myDiv.innerHTML + c + "</br>"; 

timeoutID = setTimeout("MyFunc()", 1000); 
} 
--> 
</script> 
</head> 

<body onload="MyFunc()"> 
<div id="message">
</div>
</body> 

</html>
Hope this helps.
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
Reply With Quote
Reply

Tags
thought, had, found, was

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hi thought I'd introduce myself Ducky Introduce Yourself 7 Feb 29th, 2008 21:51
thought of suggestion alexgeek Webforumz Suggestions and Feedback 7 Sep 22nd, 2007 14:15
Just A Thought JacobHaug Webforumz Cafe 6 Dec 4th, 2006 23:31
Thought I'd say hello....... caseysmom Introduce Yourself 7 Mar 18th, 2005 22:52


All times are GMT. The time now is 19:12.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43