1

I am trying to disable a textbox and click event of a button using jquery like this:

$("#NumberCalledTo").addClass("disabled");
    $("#NumberCalledTo").off('click');
    $("#NumberCalledTo").prop("readonly", true);
    $('#NumberCalledTo').tooltip({
        disabled: true
    });

Now I need to enable it on click of another button. I am doing it like this:

  $("#NumberCalledTo").removeClass("disabled");
            $("#NumberCalledTo").on('click');
            $("#NumberCalledTo").prop("readonly", false);

            $('#NumberCalledTo').tooltip({
                disabled: false
            });

but click event is not fired.

Please suggest how to fix it.

3
  • I think that there is some complex logic here! It may work simpler, you have just to make the input field active after clicking on that button. Commented May 17, 2013 at 11:55
  • What are you doing with $("#NumberCalledTo") when clicked. Commented May 17, 2013 at 11:56
  • if you disable a button you can't 'click' it surely? Commented May 17, 2013 at 12:00

4 Answers 4

1

$("#NumberCalledTo").on('click'); is not enough, you need to bind the callback function again.

$("#NumberCalledTo").on('click', callback);
Sign up to request clarification or add additional context in comments.

3 Comments

@DotnetSparrow It should be provided by you.
That is a function which works on click and i asked that to you too.
callback is the function that is executed when the event is fired. If you specified the behaviour of your button in the html (i.e. onClick="someFunction()", then the callback is someFunction.
0

Try this:

$("#NumberCalledTo").on('click', function(){
    alert('You click me!');
});

OR

$("#NumberCalledTo").on('click', callbackFunction);

 function callbackFunction()
 {
   alert('You click me!');
 }

Comments

0
$("#NumberCalledTo").click(function() {
    if ($(this).hasClass('disabled')) {
        //ENABLE CLICK
        $(this).removeClass("disabled")
                .prop("readonly", false).tooltip({
            disabled: false
        });

    } else {
        //DISABLE CLICK
        $(this).addClass("disabled")
                .prop("readonly", true)
                .tooltip({
            disabled: true
        });
    }
});

Comments

0

make a function:

 function enable(){
    $("#NumberCalledTo").removeClass("disabled");
    $("#NumberCalledTo").on('click');
    $("#NumberCalledTo").prop("readonly", false);

    $('#NumberCalledTo').tooltip({
        disabled: false
    });
 }

add as callback function:

 $('your button').on('click', enable);

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.