K
K
keche2017-11-01 16:45:50
JavaScript
keche, 2017-11-01 16:45:50

How to invert prop 'checked'?

There is a code that checks 3 parameters.

$('form').submit(function() { // проверка на пустоту заполненных полей. Атрибут html5 — required не подходит (не поддерживается Safari)
    if ($(this).find("input[name='name']").val() == '' || $(this).find("input[name='phone']").val() == '' || $('#checkbox4').prop('checked') ) {
      valid = false;
      return valid;
    }

By default, the checkbox is set to checked, so if you set the value for .prop('checked'), it turns out that submitting data from the form is prohibited if the checkbox had its checked state switched or was set by default. And it is necessary that when the checkbox in the html file is checked by default, sending data from the form is allowed. And vice versa, if the checkbox is deactivated, the checkbox is unchecked, then data transfer is prohibited.
If I set .prop('disabled') in the code, and it doesn't matter if the checkbox was enabled or not, the code somehow allows the data to go.
I think that the inversion of the code $('#checkbox4').prop('checked') with a boolean ! not.
But how to write this inversion correctly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Mashletov, 2017-11-01
@keche

... || !$('#checkbox4').prop('checked')

A
Anton Filippov, 2017-11-01
@vicodin

$('.myCheckbox').prop('checked', true);
$('.myCheckbox').prop('checked', false);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question