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
  • 66,747
  • 15
  • 75
  • 101
delphirules
  • 6,443
  • 17
  • 59
  • 108

2 Answers2

2

It should be disabled true not false, try :

$('.myinputs').each(function (i) {
    $(this).prop('disabled', true);
});
Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
  • 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
  • 331,213
  • 40
  • 305
  • 339
Anto
  • 610
  • 5
  • 13