Biplov
Biplov

Reputation: 1142

Set checkbox value when checkbox is unchecked

How can I achieve so using javascript or anything.

My checkbox looks like this

<th>{{ render_field_with_errors(form.polycarbonate_r, value="Polycarbonate", type="checkbox") }}</th>

It's flask WTF form built-in checkbox.

I want to be able to set checkbox value when it's unchecked.

Upvotes: 0

Views: 103

Answers (1)

Vig
Vig

Reputation: 339

Well the simplest way is to trigger a function when the input state changes, like this:

$('input').on('change', function() {
    if ($(this).prop('checked') == false) {
        $(this).val('New Value');
    } 
}

You can also change the value back if it's checked again. Just add an "else" statement.

Upvotes: 2

Related Questions