1

newbie to java script , I want to do like when any one click on first Button,then second button is disabled for 30 seconds , after the enabled of second button, click on second button and third button visible to the user. I know simple disable enable buttons on tutorials Thanks.

<!DOCTYPE html>
<html>
<body>

<input type="button" id="myBtn" value="My Button">

<p>Click the button below to disable the button above.</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {

     document.getElementById("myBtn").disabled = true;
}
</script>

</body>
</html>

3 Answers 3

3

Use setTimeout function to do it.

<script>
function myFunction() {
     document.getElementById("myBtn").disabled = true;
     setTimeout(function(){
       document.getElementById("myBtn").disabled = false;
     }, 5000);
}
</script>

Hope it works.

Sign up to request clarification or add additional context in comments.

3 Comments

Ooops! @AlexG, I did not know :)
@balaG u have to edit your question 500 not working 5000 will work
@balaG and Read my question please i know how to disabled and enable
1

Use setTimeout() function and variables to flag click status:

 setTimeout("myFunction();", 30000);

Comments

1

see this plunker http://embed.plnkr.co/ZUmGoGEr2TYHlfPhUJgK/preview

<!DOCTYPE html>
<html>
  <head>

    <script src="script.js"></script>
  </head>
<body>

<input type="button" id="myBtn" value="My Button"  onclick="document.getElementById('thirdBtn').style.display='block'">
<input type="button" style="display:none;" id="thirdBtn" value="Third Button">
<p>Click the button below to disable the button above.</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
document.getElementById('thirdBtn').style.display='none';
        document.getElementById("myBtn").disabled = true;
     setTimeout(function(){

       document.getElementById("myBtn").disabled = false;
     }, 30000);
}
</script>

</body>
</html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.