Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling inputs with jQuery not working

I am trying to disable some input fields using jQuery 1.4.2. This is a part of the HTML code:

<input type="text" disabled="disabled" name="nume" value="Text" />

This is the Javascript:

$('.salveaza').live('click', function(e){
    $.get(ajaxURL, $('form', itemCurent).serialize()+'&id='+itemCurent.data('id')+'&optiune=editeaza-categorie');

    // This is the code for disabeling inputs
    $('input', itemCurent).attr('disabled', 'disabled');

    itemCurent.removeClass('curent');
    $('.optiuniEditeaza', itemCurent).remove();

    e.preventDefault(); 
});

The above code doesn't work. Note that the inputs are added with jQuery, that's why I am using live, I tried all sorts of stuff.

I also tried firebug console to disable all input fields on the page and it's not working:

$('input').attr('disabled', 'disabled');

Any help will be apreciated, Thanks

like image 371
Andrei Avatar asked Jul 21 '26 00:07

Andrei


1 Answers

This should do the trick:

Disable: $('#the-field-id').attr('disabled', true);

Enable: $('#the-field-id').removeAttr('disabled');

like image 197
Zuul Avatar answered Jul 23 '26 13:07

Zuul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!