Click here to Skip to main content
16,019,876 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
when we are loading a page button should be disable for 5 sec.
after that that will enable, when we click on button that has to take to us to particular link.(onclick)
once we click on button again button should be disabled.

What I have tried:

i have tried below one

1.when we are loading a page button should be disable for 5 sec.
2.after that that will enable, when we click on button that has to take to us to perticular link.(onclick)

HTML
<input type="submit" id="submitButton"  disabled="disabled" />

JavaScript
<script type="text/javascript">
    window.onload=function() {
      setTimeout(function() {
        document.getElementById('submitButton').disabled = false;
      }, 5000); 
    }
</script>


after that when we clicked on button that has to diasble that is not happening by using above code
Posted
Updated 30-Apr-16 18:51pm
v2
Comments
George Jonsson 1-May-16 0:28am    
Where is your onClick function?
Member 12363094 1-May-16 0:30am    
that is not adding same line in that input tag
Onclick="window.open('http://www.google.co.in/')"
George Jonsson 1-May-16 0:40am    
If I understand you correctly you want to disable the button after it has been clicked.
Which function do you expect to be invoked when you click the button?
Or is the problem that the button is never enabled?
Not entirely clear.
Member 12363094 1-May-16 0:43am    
after clicking on button i can able to open link on other window also.
i am having problem with when we clicked on button that should be disable
Member 12363094 1-May-16 0:45am    
i want to invoke some link(href functionality) when i clicked on button.
what u understood is correct.

1 solution

You could try something like this

JavaScript
<script>
document.getElementById("submitButton").addEventListener("click", myFunction);

function myFunction() {
    document.getElementById('submitButton').disabled = true;
}
</script>
 
Share this answer
 
v2
Comments
Member 12363094 1-May-16 1:17am    
i have tried with ur solution but still that button is enable once we clicked otherthan that every thing is working fine.
Member 12363094 1-May-16 1:21am    
hi sorry in code u have given false instead of true.
now working fine .Thank u so much

George Jonsson 1-May-16 1:36am    
Sorry about that.
I did a classical copy&paste and forgot to change the assignment.
I updated the answer with the correct assignment.
Sergey Alexandrovich Kryukov 1-May-16 16:29pm    
getElementById("submitButton") is repeated twice.
Non-anonymous separate myFunction is totally pointless.
Correct answer but quite ugly scripting...
—SA
George Jonsson 1-May-16 17:50pm    
True. Didn't work it all through.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900