A
A
Anastasia2020-03-25 00:45:59
Django
Anastasia, 2020-03-25 00:45:59

How to control the checkbox when value is set?

$(".update").click(function() {
            if ($("#top").val('notop')) {
                $('input[name="top"]').attr('checked', false);
            } else {
                $('input[name="top"]').attr('checked', true);
            }
        });


When the button is pressed, if the input has the value "notop", check should be false.
Why is my code not working?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
szelga, 2019-09-02
@szelga

just pull data from your system in the appropriate view in any convenient (whatever) way.

S
Stockholm Syndrome, 2020-03-25
@StockholmSyndrome

$('.update').click(function() {
  $('input[name="top"]').prop('checked', $('#top').val() !== 'notop');
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question