Home / Internet & Networking / Web design / Javascript Is it possible to change "onclick" to autostart?
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] - (Bottom) Print
Author Topic: Javascript Is it possible to change "onclick" to autostart?  (Read 490 times)
terrapin
Topic Starter
Newbie



Posts: 2


« on: November 12, 2009, 02:05:40 PM »

I have a script that is a counter that keeps track of how much money the city of SF is collecting from parking tickets.  It works just fine with onclick.  However, I would love for it to start counting when the page opens. I would also love it if there could be commas inserted in between every 3rd number.   

The website is www.findingthesweetspot.com, and the counter to which I am referring is at the top right corner of the home page.  There is another site   www.costofwar.com that autostarts and keeps a live count.  This would be the ultimate goal to have a counter like this one, but with different numbers.  Thanks for your help in advance.

Here is the code:
<div id="apDiv33"><form>
  <input name="Button" type="button" class="style2" style="font-size: 24px; font-weight: bold; color: #F00;" onClick="timedCount()" value=".">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input name="999" type="text" id="txt" style="font-size: 18px; font-weight: bold;" value="" size="11" maxlength="11">
</form></div>


<script type="text/javascript"style="font-size: 34px; font-weight: normal;">
var c=959071;
var t;
function timedCount()
{
document.getElementById('txt').value="$102,"+c;
c=c+1;
t=setTimeout("timedCount()",97);
}

</script>
IP logged
Bannana97
Intermediate



Posts: 145



Owner of HerbertsWorld Corporation

HerbertsWorld - Free Websites
« Reply #1 on: November 13, 2009, 06:27:42 AM »

Hi,

Just add the onClick code to a javascript tag UNDER the function.


Code: [Select]
<div id="apDiv33"><form>
  <input name="Button" type="button" class="style2" style="font-size: 24px; font-weight: bold; color: #F00;" onClick="()" value=".">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input name="999" type="text" id="txt" style="font-size: 18px; font-weight: bold;" value="" size="11" maxlength="11">
</form></div>


<script type="text/javascript"style="font-size: 34px; font-weight: normal;">
var c=959071;
var t;
function timedCount()
{
document.getElementById('txt').value="$102,"+c;
c=c+1;
t=setTimeout("timedCount()",97);
}
timedCount();
</script>
IP logged

Thanks
Bannana97
Pages: [1] - (Top) Print 
Home / Internet & Networking / Web design / Javascript Is it possible to change "onclick" to autostart? « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.111 seconds with 20 queries.