Forum Moderators: open

Message Too Old, No Replies

Submit button appears after a set time limit

         

StoutFiles

1:37 pm on Aug 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Anyone have experience with making a submit button appear after a set time limit? I need the majority of my users to stay on a page longer then they might want to, hence the submit button can't be clickable until the time limit has expired.

lostdreamer

2:23 pm on Aug 16, 2010 (gmt 0)

10+ Year Member



a combination of setTimeOut and button.disabled = false should do it I guess?


<script language="javascript">
// make sure the button is disabled first...
document.getElementById('btnNext').disabled = true;
// then enable the button in 5 seconds....
setTimeout("enableButton", 5000);
function enableButton() {
document.getElementById('btnNext').disabled = false;
}
</script>


I have JS disable the button first (instead of setting the button to disabled in the HTML) so people without JS will just get a form that works...

Good luck

Fotiman

3:01 pm on Aug 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That should work. I would modify that example slightly to:
1. Remove the invalid language attribute and replace it with the type attribute.
2. Don't pass a string in setTimeout, pass a function reference.

So:

<script type="text/javascript">
function enableButton() {
document.getElementById('btnNext').disabled = false;
}
// make sure the button is disabled first...
document.getElementById('btnNext').disabled = true;
// then enable the button in 5 seconds....
setTimeout(enableButton, 5000);
</script>