removeClass does not work

0

I need to validate two fields in my form to enable the Submit button for the end user, but removeClass('disabled') is not working.

    $('#main-form').on(function () {
        simCode = $('#main-form [name=code]').val().length;
        carrierId = $('#main-form [name=carrierId]').val();

        if (simCode == 20 || carrierId != "null") {
           $('#save').removeClass('disabled');
        }
    });

Remembering that simCode receives the values of an input type text and carrierId receives the value of a select option

    
asked by anonymous 10.05.2018 / 17:22

2 answers

3

disabled is not a class, it is a property.

Use:

$('#save').prop('disabled', true);

Example:

function desabilita(){
  $('#save').prop('disabled', true);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><ahref="javascript:void(0)" onclick="desabilita()">Clique aqui para desabilitar o botão abaixo</a>
<br>
<button type="button" id="save">Botão</button>
    
10.05.2018 / 17:41
2

You have not included your html, but it seems that disabled is not a style class but an element attribute.

$('#main-form').on(function () {
    simCode = $('#main-form [name=code]').val().length;
    carrierId = $('#main-form [name=carrierId]').val();

    if (simCode == 20 || carrierId != "null") {
       $('#save').attr('disabled', false);
    }
});
    
10.05.2018 / 17:41