/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] timer and submit button

How can I revers this.
Right now it disables the submit button after x amount of seconds, how can i make the submit button disabled now, and after x amount of seconds, it enables it ?

[code=php]
<body>

<script type=”text/javascript”>
seconds = 30; // number of seconds to wait
id = ‘submit’;
onload = function() {
timestamp = new Date();
time = timestamp.getTime();
}
function countdown() {
c_timestamp = new Date();
c_time = c_timestamp.getTime();
if (Math.floor((c_time – time)/1000) == seconds) {
document.getElementById(id).disabled = true;
clearInterval(timer);
}
}
timer = setInterval(“countdown()”, 1000);
</script>
</head>
<body>
<div id=”countdown”></div>
<script> startInterval();
</script>
<form action=””>
<p><input type=”submit” name=”submit” id=”submit” value=”submit” /></p>
</form>
</body>
[/code]

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@shane_carrAug 25.2006 — [code=php]<script type="text/javascript">
seconds = 2; // number of seconds to wait
seconds1 = 2; // num of secs to activate
id = 'submit';
onload = function() {
timestamp = new Date();
time = timestamp.getTime();
}
function countup(){
cu_timestamp = new Date();
cu_time = cu_timestamp.getTime();
if (Math.floor((cu_time - time)/1000) == seconds1) {
document.getElementById(id).disabled = false;
clearInterval(timer);
timestamp = new Date();
time = timestamp.getTime();
timer = setInterval("countdown()", 1000);
}
}
function countdown() {
c_timestamp = new Date();
c_time = c_timestamp.getTime();
if (Math.floor((c_time - time)/1000) == seconds) {
document.getElementById(id).disabled = true;
clearInterval(timer);
timestamp = new Date();
time = timestamp.getTime();
timer = setInterval("countup()", 1000);
}
}
timer = setInterval("countdown()", 1000);
</script>
</head>
<body>
<div id="countdown"></div>
<script> startInterval();
</script>
<form action="">
<p><input type="submit" name="submit" id="submit" value="submit" /></p>
</form>[/code]
Copy linkTweet thisAlerts:
@slimjimauthorAug 26.2006 — Ok I am confused, this does disable it, but also enables it too, if i set them both at 2 seconds, then every 2 seconds it keeps disabling it and enableing it every 2 seconds.

All I am trying to do is keep it disabled for x amount of seconds and then it becomes enabled for good.
Copy linkTweet thisAlerts:
@shane_carrAug 26.2006 — Okay, I see now. In countup() remove these lines:

timestamp = new Date();

time = timestamp.getTime();

timer = setInterval("countdown()", 1000);

or, start out with the button disabled="disabled" in the parameters in html, and change "...disabled = true" to "false" and use your old code.
Copy linkTweet thisAlerts:
@slimjimauthorAug 26.2006 — That worked, I used the old code and disabled the button before the function
Copy linkTweet thisAlerts:
@shane_carrAug 26.2006 — I'm glad that you figured it out! ?
×

Success!

Help @slimjim 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 5.24,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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