/    Sign up×
Community /Pin to ProfileBookmark

javascript stopwatch

H there this is my first post! I wanted to ask if anyone could come up with something to solve my quite simple program. With the following code you can program a simple stopwatch, what I want to add is a button than when the stopwatch is stopped, and you click, that the recorded time is recorded and displayed elsewhere (without reloding)

the code is the following…

[code]
<html>
<head>
<script type=”text/javascript”>
var c=0;
var t;
var timer_is_on=0;

function timedCount()
{
document.getElementById(‘txt’).value=c;
c=c+1;
t=setTimeout(“timedCount()”,1000);
}

function doTimer()
{
if (!timer_is_on)
{
timer_is_on=1;
timedCount();
}
}

function stopCount()
{
clearTimeout(t);
timer_is_on=0;
}
</script>
</head>

<body>
<form>
<input type=”button” value=”Start count!” onClick=”doTimer()”>
<input type=”text” id=”txt”>
<input type=”button” value=”Stop count!” onClick=”stopCount()”>
</form>
</body>
</html>
[/code]

I&#180;m aware im quite a newbie to all this and that my question is quite simple and maybe to vague but I hope you can help me anyways

Cheers to you all and thanks in advance

Trufa

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERDec 21.2009 — H there this is my first post! I wanted to ask if anyone could come up with something to solve my quite simple program. With the following code you can program a simple stopwatch, what I want to add is a button than when the stopwatch is stopped, and you click, that the recorded time is recorded and displayed elsewhere (without reloding)

the code is the following...

<i>
</i>[COLOR="Red"][SIZE="4"]// Put your code between the [ code] and [ /code] tags (without spaces)
// to make it stand out and be easier to read by the forum members.[/SIZE][/COLOR]



I´m aware im quite a newbie to all this and that my question is quite simple and maybe to vague but I hope you can help me anyways

Cheers to you all and thanks in advance

Trufa[/QUOTE]


Unclear of the request ... ?

Where is the 'elsewhere'?

Same page?

Pop-up <div> section?

Opened in a new window?

Passed to an existing page?

What do you mean by 'recorded'?

Saved to a file?

Saved to a cookie?

Passed to the server?

BTW: Welcome to the forum!

?
Copy linkTweet thisAlerts:
@jmvarelasudyauthorDec 21.2009 — hey sorry about JMARKER and thanks for the advice, the thing is I have two big problems:

1) English is not my language

2) I&#180;m a COMPLETE newbie!!!!!!

I could solve my problem in another forum anyway:

I leave it in case anybody has the same doubt!

[CODE]<html>
<head>
<script type="text/javascript">
var c=0;
var t;
var timer_is_on=0;
var x=1;


function timedCount()
{
document.getElementById('txt').value=c;
c=c+1;
t=setTimeout("timedCount()",1000);
}

function doTimer()
{
if (!timer_is_on)
{
timer_is_on=1;
timedCount();
}
}

function stopCount()
{
clearTimeout(t);
timer_is_on=0;
}

function saveSeconds()
{
var seconds = document.getElementById('txt').value;
if (!timer_is_on && seconds != '')
{
document.getElementById('save').value = document.getElementById('save').value + x++ + ":" + seconds + 'n';
c=0;
document.getElementById('txt').value = '';
}
}



</script>
</head>

<body>
<form>
<input type="button" value="Start count!" onClick="doTimer()">
<input type="text" id="txt">
<input type="button" value="Stop count!" onClick="stopCount()">
<input type="button" value="Save" onClick="saveSeconds()">
<br>
<textarea id="save" name="save" cols="10" rows="10"></textarea>
</form>
</body>
</html>[/CODE]


I have another question but will go in a new thread!

Cheers! and thanks for the welcoming!
×

Success!

Help @jmvarelasudy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...