0

I have a form with several inputs. For some reason, I want specific inputs with specific class not be posted when the user submits the form.

I already tried disabling the specific inputs like:

$('.myinputs').each(function (i) {
    $(this).prop('disabled', false);
});

This command would disable the inputs, but they still are being posted.

Any hints ?

Thanks

Zakaria Acharki
  • 65,304
  • 15
  • 70
  • 95
delphirules
  • 5,815
  • 14
  • 51
  • 95

2 Answers2

2

It should be disabled true not false, try :

$('.myinputs').each(function (i) {
    $(this).prop('disabled', true);
});
Zakaria Acharki
  • 65,304
  • 15
  • 70
  • 95
  • 2
    While `'disabled'` will be cast to `true` when assigned to thh `disabled` property, you should use a boolean and not a string. – Quentin Jan 24 '19 at 15:26
1

You can refer to this answer

You might need to put your logic onSubmit Event

$(function()
{
    $("form").submit(function()
    {
        $(this).children('.myinputs').attr("disabled", "disabled");

        return true; // ensure form still submits
    });
});
Rory McCrossan
  • 319,460
  • 37
  • 290
  • 318
Anto
  • 590
  • 5
  • 13