0

I'm trying to disable a textbox/and button for few seconds after the "Send button" has been clicked and then enable it again as well empty the textbox. But it doesn't work out.

I have an onSuccess() function in JavaScipt in combination with using the REST API:

function onSuccess(data, request) {
    $("#articleData").html("<span class='red'>Message sent </span>");
    if ($("#articleData").val().length > 0) {
        $("#articleData").val("");
    }
    $("#articleData").empty();
    disable();
}

function disable() {
    x = document.getElementById("savebutton");
    x.disabled=true;
    setTimeout(enable, 3000);
}

function enable() {
    x.disabled=false;
}
1
  • whats the error?
    – Taran Goel
    Jan 27, 2016 at 13:58

1 Answer 1

0

using jquery:

function disable(){
    $("#savebutton").prop("disabled", true);
  setTimeout(function(){
    $("#savebutton").prop("disabled", false);
  }, 3000);
}

using javascript:

function disable(){
  document.getElementById("savebutton").disabled = true;
  setTimeout(function(){
    document.getElementById("savebutton").disabled = false;
  }, 3000);
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.