Alex Rivera | Logout

Event on a disabled input

Asked 2010-06-23T09:09:26.457
295

Apparently a disabled <input> is not handled by any event

Is there a way to work around this issue ?

<input type="text" disabled="disabled" name="test" value="test" />
$(':input').click(function () {
    $(this).removeAttr('disabled');
})

Here, I need to click on the input to enable it. But if I don't activate it, the input should not be posted.

Edit
Report

2 Answers

16

I would suggest an alternative - use CSS:

input.disabled {
    user-select : none;
    -moz-user-select : none;
    -webkit-user-select : none;
    color: gray;
    cursor: pointer;
}

instead of the disabled attribute. Then, you can add your own CSS attributes to simulate a disabled input, but with more control.

answered 2012-01-07T09:49:03.080
-2

suggestion here looks like a good candidate for this question as well

Performing click event on a disabled element? Javascript jQuery

jQuery('input#submit').click(function(e) {
    if ( something ) {        
        return false;
    } 
});
answered 2011-11-30T20:45:13.733

Your Answer