How to set the input tag as enabled?

2511 views javascript
-1

var startat = 5;
function disableRegBtn(bdisable){
    document.getElementById('regBtn').disabled=bdisable;
}
 
function showTime(){
    if(startat == 0){
        clearInterval(timeId);
        document.getElementById("p1").innerHTML = "please register now";
        disableRegBtn("enabled");
        return;
        }
    document.getElementById("p1").innerHTML = "please register in  " + startat + "  second(s)";
    startat--;      
}
window.onload=function(){
    document.getElementById('taid').readOnly=true;
    disableRegBtn(true);
    timeId=setInterval("showTime()",1000);
}
 
<textarea id="taid" cols="30" rows="5">Registration Agreement:
1.xxxxxx
2.xxxxxx
3.xxxxxx
</textarea> <p id="p1"><input id="regBtn" type="button" value="register" /></p>
 

I want to make people read the registration agreement at least 5 seconds before they submit their registration,when 5 second is over,please register now can show in webpage,how to make <input id="regBtn" type="button" value="register" /> work?

I make some tries for disableRegBtn() in showTime function.

disableRegBtn(false)
disableRegBtn("false")
disableRegBtn("disabled")
disableRegBtn("enabled")  

None of them can take effect.

answered question

Note your code is currently deleting your button, ie innerHTML of p1 is being overwritten, so there is no way of re-enabling it since you got rid of it all together. The disableRegBtn(false) will work as the disabled property is a boolean value.

1 Answer

6

your button deleted while doing document.getElementById("p1").innerHTML = "please register in... just add the button again after timeout

var startat = 5;

function disableRegBtn(bdisable) {
  document.getElementById('regBtn').disabled = bdisable;
}

function showTime() {
  if (startat == 0) {
    clearInterval(timeId);
    document.getElementById("p1").innerHTML = '<input id="regBtn" type="button" value="register" />';
    return;
  }
  document.getElementById("p1").innerHTML = "please register in  " + startat + "  second(s)";
  startat--;
}
window.onload = function() {
  document.getElementById('taid').readOnly = true;
  disableRegBtn(true);
  timeId = setInterval("showTime()", 1000);
}
<textarea id="taid" cols="30" rows="5">Registration Agreement:
1.xxxxxx
2.xxxxxx
3.xxxxxx
</textarea>
<p id="p1"><input id="regBtn" type="button" value="register" /></p>

posted this

Have an answer?

JD

Please login first before posting an answer.