Recent Widgets


Register for DashboardWidgets

Recent Forums Posts

Partners


iCompositions

MacDesktops.net

RSS Showcase
RSS Comments
RSS Forums

This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. Posted in: Widget Central

Refreshing a counter in a widget??

Author Message
JohnGaver



Joined: 17 May 2005
Posts: 20
Location: Texas

Posted: Tue May 17, 2005 - 7:50 am    Post subject: Refreshing a counter in a widget?? Reply with quote

I have a widget that includes a counter that increments over time. Right now, I have everything working, but the only way that I have been able to increment the number on the screen, is to very ungracefully refresh the html page every 300 seconds (5 minutes). For some reason, I have been unable to get the JS to refresh just the text on the page.

I have tried several variations. Most caused more problems than they fixed, so at the present time, I am keeping it simple. I have an image background and a CSS style that places the JS output in the appropriate place, over that background. The html calls the JS function as follows:

Code:
<div class='bg'>
    <script type="text/javascript" lanugage="JavaScript">
        document.write(sdCount() + " times.");
    </script>
</div>


Refreshing the entire widget every 5 minutes is such an un-kewl way to refresh the counter. I want to update just the number on the screen as the output of sdCount() increments (every 13 seconds). Any ideas??? Thanks.
View user's profile Send private message Send e-mail Visit poster's website Widgets
Chris



Joined: 27 Jan 2005
Posts: 344
Location: Durham, UK

Posted: Tue May 17, 2005 - 7:57 am    Post subject: Reply with quote

I'd recommend to never use document.write, btw. Just use DOM manipulation instead.

HTML:
Code:

<div class="bg" id="bg">
    <script type="text/javascript" lanugage="JavaScript">
        document.write(sdCount() + " times.");
    </script>
</div>


Javascript;
Code:

function getCount() {
    document.getElementById("bg").innerText = sdCount() + " times.";

    setTimeout("getCount()", 13000);
}

window.onload = getCount;


or use setInterval, or whatever - it's up to you. Also, despite advocating DOM methods at the beginning of this post, innerText is not an actual DOM method, but'll work just fine (if you want to be strict, create a text node with the required text in it, and replace the first child of bg).
View user's profile Send private message Send e-mail Visit poster's website AIM Address Widgets
JohnGaver



Joined: 17 May 2005
Posts: 20
Location: Texas

Posted: Tue May 17, 2005 - 1:08 pm    Post subject: Thanx - That worked Reply with quote

Thanks, Chris. That worked.

I had tried something very similar last night (correction - very early this morning), but as they say, close only counts in horseshoes and bombs. It's amazing what a person can do with a little mental nudge and a few hours of sleep.
View user's profile Send private message Send e-mail Visit poster's website Widgets
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.

 
Powered by phpBB © 2001, 2002 phpBB Group