I have a mvc 4 website that is controlled by a windows form application. In this winform you can set a start and end time for the auction that will run on the website. Once a user places a bid they can remove it up to a hour before auction ends. How do I go about disabling this remove button when current time is less than a hour from end time? Thanks for any help.
Asked
Active
Viewed 699 times
0
-
you need to look into Ajax. Are you using a Javascript Lib like jQuery? – hammus Dec 02 '13 at 21:08
-
http://stackoverflow.com/questions/8455383/jquery-datepicker-date-diff-calculation – Matt Bodily Dec 02 '13 at 21:14
-
Yes I was trying to do it in JavaScript or jQuery but I just cant figure it out. – user2989650 Dec 02 '13 at 21:56
2 Answers
1
Add a timer on the view so that when its loaded the datetime
value for end of the auction will be used to deactivate the button.
You could do something like the following in jquery in the view (this is rough code off the top of my head):
<script type="text/javascript">
$(function ()
{
// essentially subtract your db value from now
var auctionEndTime = datetimevaluefromthedatabase - datetimenow
// if there's still time - greater than 1 hour then set timer
if (auctionEndTime > 1)
{
// note: you'll need milliseconds for the timeout
var initTimer = setTimeout(function () { disableButton() }, auctionEndTime);
}
else
{
disableButton();
}
function disableButton()
{
$('input:submit').attr("disabled", true);
}
});
</script>

Stinky Towel
- 768
- 6
- 26
0
Solution would be setting interval to check on state with $.ajax or any other ajax implementation, an doing unbind of the click or removing button when time comes.
You can also do one single check on time left, then put the time in the memory and then check for the desired time in equal intervals.
Second solution is les precise due the javascripts peculiar time handling but this would put less load on your backend and maybe database.

Rastko
- 477
- 2
- 7