mardi 27 juin 2017

JQuery reset value of text input when checkbox is unchecked

I have a fieldset in my form that has a check box tied to a text input. When the checkbox is checked/unchecked it toggles the readonly attribute of the text input.

When the checkbox is unchecked I would like the text input value to reset to 0.

Here is my

<label for="device-9102" class="form-partner-label"><input type="checkbox" class="quote-chkbox" id="9102-chk"> 9102 IP Phone</label>
<input type="text" name="9102-quantity" class="form-endpoint-qty form-control" id="form-partner-9102" readonly value="0">

Here is the JQuery that currently sets the readonly value for the text input:

$("#9102-chk").change(function() {
        $("#form-partner-9102").prop("readonly", !$(this).is(":checked"));
});

How do I reset the value of the text input to 0 when the checkbox is unchecked?




Aucun commentaire:

Enregistrer un commentaire