jquery - How can I show an html area when a custom checkbox is checked? -
the issue i'm having telling when custom checkbox has been checked? when checked i'd show itemshipping div. far can tell, input isn't being checked, :after element on label changes. appreciated :)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <link href="https://cdnjs.cloudflare.com/ajax/libs/awesome-bootstrap-checkbox/0.3.7/awesome-bootstrap-checkbox.css" rel="stylesheet"/> <div class="checkbox checkbox-primary"> <input class="styled" type="checkbox" id="itemwillship" name="itemwillship"> <label for="itemwillship"> will ship</label> </div> <div id="itemshipping"> <div class="col-sm-12 form-group"> <label for="productshippinginfo" class="required">shipping information</label> <textarea class="form-control" rows="4" id="productshippinginfo" name="productshippinginfo"></textarea> <span id="error" class="sr-only">(error)</span> <span id="helpblock" class="help-block">add information shipping details such price, shipping method, ect.</span> </div> </div>
// reference elements var itemshipping = $('#itemshipping'); var checkbox = $('#itemwillship'); // function hiding , showing div function toggleitemshipping(){ itemshipping.toggle(checkbox.prop('checked')); } // event handler clicking checkbox checkbox.on('change', toggleitemshipping); // when page loads set correct state toggleitemshipping();
here's full thing:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <link href="https://cdnjs.cloudflare.com/ajax/libs/awesome-bootstrap-checkbox/0.3.7/awesome-bootstrap-checkbox.css" rel="stylesheet"/> <div class="checkbox checkbox-primary"> <input class="styled" type="checkbox" id="itemwillship" name="itemwillship"> <label for="itemwillship"> will ship</label> </div> <div id="itemshipping"> <div class="col-sm-12 form-group"> <label for="productshippinginfo" class="required">shipping information</label> <textarea class="form-control" rows="4" id="productshippinginfo" name="productshippinginfo"></textarea> <span id="error" class="sr-only">(error)</span> <span id="helpblock" class="help-block">add information shipping details such price, shipping method, ect.</span> </div> </div> <script> // reference elements var itemshipping = $('#itemshipping'); var checkbox = $('#itemwillship'); // function hiding , showing div function toggleitemshipping(){ itemshipping.toggle(checkbox.prop('checked')); } // event handler clicking checkbox checkbox.on('change', toggleitemshipping); // when page loads set correct state toggleitemshipping(); </script>
Comments
Post a Comment