Jump to content

Change auto disable time from 1min to 41seconds


anthelo

Recommended Posts

Now my button is auto shown after 1min, how i can make it to be visablee after 0min & 41second

 

<body>
    <button>My button</button>
</body>
​
function enableButton() {
    $("button").prop("disabled", "");
}

$(function() {
    var minutes = 1; // time to be disabled
    var time = minutes * (1000 * 60);
    
    $("button").prop("disabled", "disabled"); // Disable the button onload
    
    setTimeout(function() {
        enableButton();
    }, time);
});​

 

Live demo: http://jsfiddle.net/RrBKr/9/

 

Regards

 

Link to comment
Share on other sites

They ain't bein' mean. You just need to try and think for yourself rather than ask someone to fix everything for you. This is not a site where people do work for you, they help you with your own work.

 

The only thing you should possibly need help on is knowing the time is in milliseconds. This means that 1000 is a second. So, 60 * 1000 is a minute.

 

Also, please change the variable name to seconds just because it'd drive me mad if you left it as minutes. And that should tell you exactly how to do it.

Link to comment
Share on other sites

  • 1 month later...

Let me start by saying that you should make it a point to go to your favorite book store and get your hands on an introductory level javascript book. Your understanding of programming is obviously very rudimentary and such a book would be a good place to start and give you a solid foundation on which to build. The members of this forum are here to help, and though it may seem that their comments were derogatory in nature, they said what they did with the greatest of intentions. Someone with a solid foundation in the basics of programming should quickly realize that "var time" holds the amount of time they are looking for and had you put some more time into considering the code and what it was doing and what you wanted it to do, this should have become apparent. It is like a teacher giving you hints and suggestions to get you to figure things out for yourself and learn rather than just handing you an answer sheet with all the correct answers for the test. If someone just told you the answer was var time = 41000; then you would learn nothing. Now let me explain why this is the case. In the code you have var minutes is a human readable, easy to understand representation of time. There is no tricky math required to know that if you want the button to become enabled in 1 minute the value should be 1 and for 5 minutes the value should be 5. The time variable (var stands for variable and is how variables are defined in javascript) does the tricky math since javascript measures the passage of time in milliseconds. var time = minutes * ( 1000 * 60 ); means that we take the number of minutes and multiply it by the number of milliseconds in a minute, so that's 1 x ( 1000 x 60 ). From math we know that we process the parenthesis first so it becomes 1 x ( 60000 ) which is simply 60000 milliseconds in 1 minute. If we were doing 5 minutes it would be 5 x 60000 which would be 300000 milliseconds in 5 minutes. If we want 41 seconds in a time format that javascript can work with it would be 41 x 1000 which is 41000.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.