9 Replies - 11785 Views - Last Post: 02 July 2010 - 08:48 PM

#1 owkaye  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-November 08

Disable form until timer counts down to zero ...

Posted 16 November 2008 - 08:28 PM

I'm designing a live auction website and I need to limit the number of posts each bidder makes. My current goal is to allow one bid every 60 seconds.

My concept is to allow the first post to be submitted normally, then disable the form -- specifically the submit button -- until the bidder waits for the 60 second countdown timer to expire.

During the 60 seconds after each post while the countdown timer is 'counting down' I hope to display a semi-transparent countdown value (in seconds) on top of the form. When the countdown timer reaches zero the transparent timer display should disappear, then the submit button should become active again.

An alternative to a transparent countdown on top of the form is to display number of seconds remaining in the submit button itself. Then when the timer reaches zero the submit button once again becomes active and displays "submit".

My questions are:

Can this be done entirely in javascript or will it require additional tools?

If it takes more than just javascript, what are the additional requirements?

Is This A Good Question/Topic? 0
  • +

Replies To: Disable form until timer counts down to zero ...

#2 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 205
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Re: Disable form until timer counts down to zero ...

Posted 16 November 2008 - 08:38 PM

This can absolutely be done with javascript, but you will want to verify the timing on the server side too, since javascript injection would allow a malicious user to modify the timing.
Was This Post Helpful? 0
  • +
  • -

#3 owkaye  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-November 08

Re: Disable form until timer counts down to zero ...

Posted 16 November 2008 - 10:38 PM

Thanks William_Wilson, I appreciate your confirmation.

I will need a very fast server in order to keep up with the 500 hits per seconds the incoming bids will generate. Checking each bid during the auction will add to the response time and may bog the server down. Therefore I think it will be faster to accept and log each bid on the server, even if it's a 'cheating bid'. Then after the auction is ended and the server load returns to normal, I can parse the logs, identify the bidders who tried to cheat (by modifying the timing, etc.) and just disqualify their bids.

Basically I'll use the Javascript to limit the bidding frequency for the folks who want to play the game honestly, and I'll do an after-the-fact bidding evaluation later. Since there's a limit of 60 bids per person in a one-hour auction it's easy to see who posted more bids simply by counting the logs.

:)
Was This Post Helpful? 0
  • +
  • -

#4 owkaye  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-November 08

Re: Disable form until timer counts down to zero ...

Posted 02 February 2009 - 05:52 PM

I created this thread a couple months ago, and I've tried to find an online resource or some examples I could use to accomplish my goal of displaying the "seconds remaining until button is enabled" in the submit button itself, but I have not succeeded in this effort and it's getting frustrating to take so long on such a simple feature. All I want is for the submit button to display text like this when it is enabled:

"Click here to submit your bid"

and text like this to be displayed when it is disabled:

"Please wait X seconds to place your next bid"

... where the "X" is the number of seconds remaining before the button is automatically enabled. Naturally this text should update once each second so the "X" becomes a countdown timer.

Here is the code I'm planning to use for the basic re-enabling of the submit button. I found this online and tested it and it works properly:

<script type="text/javascript">
window.onload=function(){
	//this calls enableIt 5 seconds after the page has loaded
	setTimeout(enableIt,5000)
}
function enableIt(){
document.getElementById('send').disabled=false;
}
</script>

<input id="send" type="submit" disabled="disabled" name="send" value="submit"/>



... but of course it does not display the submit button text the way I want it to when it is disabled, and this is the part I need help with.

What I would really love is to ask someone to post a function that I can add to this code to make it display the submit button text as described above. Then again I'm aware of this rule and I don't want to break it:

Quote

We will not do your homework for you! Do not ask us to give you code.


So can someone please post a link or send me what I need privately so I can get this feature finished once and for all? Thanks in advance for any help you can provide ... :)
Was This Post Helpful? 0
  • +
  • -

#5 JohnWaters  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 138
  • Joined: 28-November 08

Re: Disable form until timer counts down to zero ...

Posted 02 February 2009 - 06:28 PM

opps. see below ! :)

This post has been edited by JohnWaters: 02 February 2009 - 06:42 PM

Was This Post Helpful? 0
  • +
  • -

#6 JohnWaters  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 138
  • Joined: 28-November 08

Re: Disable form until timer counts down to zero ...

Posted 02 February 2009 - 06:41 PM

Personally I think your going about this all wrong.

1) Why dont you initially set the submit button to enabled and also the value.
<input id="send" type="submit" name="send" value="Click here to submit your bid"/>


2) When the user submits the form ensure you call a Javascript function first.
<form onsubmit="return validate(this)" ... >


3) Use the Javascript function to set what ever you want.
var seconds = 60;
var timeLimit = seconds;

function validate(myForm)
{
	myForm.send.disabled = true;
	setValue(myForm);
}
function setValue(myForm)
{
	myForm.send.value = "Please wait "+timeLimit +" seconds to place your next bid";
	timeLimit --;
	if(timeLimit >= 0)
		 setTimeout("setValue(myForm)",1000)
	else
		 enableIt(myForm)

}
function enableIt(myForm){
	myForm.send.value = "Click here to submit your bid";
	myForm.send.disabled = false;
	timeLimit = seconds;
}




Now I have not tested this code so please tesst it well, but I hope this sends you on the correct path.
ALSO just be aware that Javascript and CSS can be manipulated to remove the disable part of the button and therefore be able to submit as many times as they want so take the previous advice and check on the server side.

All the best :)

This post has been edited by JohnWaters: 02 February 2009 - 06:43 PM

Was This Post Helpful? 1
  • +
  • -

#7 owkaye  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-November 08

Re: Disable form until timer counts down to zero ...

Posted 02 February 2009 - 09:20 PM

Quote

Personally I think your going about this all wrong.
I wouldn't be the least bit surprised. I'm an expert at server-side scripting but javascript in the browser is so new to me that my only realistic options (until I learn more) are to grab examples other people have posted online -- some of which don't work at all and others that are shall we say "less than appropriate" for my needs but nevertheless they sort of work sometimes -- and try to figure out how they do what they do so I can modify them for my specific needs.

Quote

Why don't you initially set the submit button to enabled and also the value.
Okay I see where you're coming from. You want the default to be button-enabled with the static value, then when the form is submitted you want to disable the button and display the countdown timer. At first I thought this might make more sense than the way I've proposed too, but then I got to thinking about it and I'm not so sure that it's the right way to go. Please let me ask this question so I will better understand your thoughts:

Are you suggesting that I intercept the post with a javascript when the visitor clicks the submit button, then disable the form for 60 seconds at this time, and then allow the post to be submitted after the 60 second timer has expired?

I think this is what you're suggesting. If I'm correct then this won't do what I want. I only want to make the visitor wait 60 seconds since his last post, not 60 seconds after he clicks the submit button. If he has already waited 60 seconds since his last post he should not have to wait any longer before posting again, because he has already waited the required 60 seconds. Do you see what I'm getting at here?

Quote

Be aware that Javascript and CSS can be manipulated to remove the disable part of the button and therefore be able to submit as many times as they want so take the previous advice and check on the server side.
I'm definitely going to check this on the server side, but for the 'honest' visitors I want to prevent posting too frequently in the browser in order to reduce the load on the server. After analyzing the server logs at the end of each auction I will simply disqualify anyone who has placed his/her bids too frequently, that's all.

This post has been edited by owkaye: 02 February 2009 - 09:21 PM

Was This Post Helpful? 0
  • +
  • -

#8 JohnWaters  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 138
  • Joined: 28-November 08

Re: Disable form until timer counts down to zero ...

Posted 03 February 2009 - 03:56 AM

Sorry my mistake regarding the form onsubmit maybe what you need is AJAX.

So use onclick="validate(document.myForm)" on your submit button.

Then make an AJAX request within that Javascript function to ensure your page doesnt refresh.

:)
Was This Post Helpful? 0
  • +
  • -

#9 owkaye  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-November 08

Re: Disable form until timer counts down to zero ...

Posted 03 February 2009 - 05:43 AM

Quote

So use onclick="validate(document.myForm)" on your submit button. Then make an AJAX request within that Javascript function to ensure your page doesn't refresh.
This sounds interesting. I guess the first thing I should do if I attempt to approach the problem this way is to figure out how to make an AJAX request ... :)
Was This Post Helpful? 0
  • +
  • -

#10 timmyyap  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-July 10

Re: Disable form until timer counts down to zero ...

Posted 02 July 2010 - 08:48 PM

hi,
i m designing an auction website. i would like to to disable the form when the countdown timer reaches zero. Is it possible to do it? pls advise...thks...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1