Reputation: 2748
Good day, I'm trying to clear a form depends on checkbox changes
. It's working fine with the clear form
. But the probem is my checkbox isn't checked. Any solution with that ? thanks in advance and sorry for my bad english.
$(document).ready(function() {
$("#general").change(function() {
$('.form-horizontal').trigger("reset");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<fieldset class="group-border">
<legend class="group-border">Form</legend>
<form class="form-horizontal" method="post">
<div class="form-group">
<label class="col-sm-3 control-label">Transaction No</label>
<div class="col-sm-6">
<input type="text" readonly required autocomplete="off" name="shippingno" id="shippingdoc" class="form-control" />
</div>
<div class="checkbox">
<label>
<input id="general" type="checkbox">General
</label>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Reference</label>
<div class="col-sm-6">
<input type="text" required autocomplete="off" name="shippingno" id="shippingdoc" class="form-control" />
</div>
<button class="btn btn-submit" id="reference" type="button">...</button>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Document No</label>
<div class="col-sm-6">
<input type="text" required autocomplete="off" name="docno" class="form-control" />
</div>
</div>
</form>
</fieldset>
Upvotes: 1
Views: 58
Reputation: 17868
One way to achieve this, you can also set the value back again after you reset the form.
$(function () {
$("#general").on('change', function () {
var $cb = $(this),
isChecked = $cb.prop('checked');
$('.form-horizontal').trigger("reset");
$cb.prop('checked', isChecked);
})
})
Upvotes: 3