I create a checkbox and its 2 depending input fields, when I check the check box 2 input fields appear then I write some in that but when I unchecked the checkbox that input fields cannot reset that value and submitted forward. I want simple when I uncheck then check box its depending input fields reset their values to default. Here is my code:
<input id="return" type="checkbox" value="" name="return">Return Journey
<div class="bkt_return_journey" id="altway" style="display: none;">
<input type="text" name="datebr" id="datepickerr" class="booktaxti_input" /></div>
<script type="text/javascript">
$('#return').live('change', function(){
if ( $(this).is(':checked') ) {
$('#altway').show();
} else {
$('#altway').hide();
}
});
</script>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<input id="return" type="checkbox" value="" name="return">Return Journey
<div class="bkt_return_journey" id="altway" style="display: none;">
<input type="text" name="datebr" id="datepickerr" class="booktaxti_input" />
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#return').on('click', function(){
if ( $(this).is(':checked') ) {
$('#datepickerr').val('');
$('#altway').show();
} else {
$('#altway').hide();
}
});
});
</script>
</body>
hope it could help you out
<input id="return" type="checkbox" value="" name="return">Return Journey
<div class="bkt_return_journey" id="altway" style="display: none;">
<input type="text" name="datebr" id="datepickerr" class="booktaxti_input" /></div>
<script type="text/javascript">
$(document).on('click','#return', function(){
if ( $(this).is(':checked') ) {
$('#altway').show();
} else {
$('#altway').hide();
}
});
</script>
You can change your code as follow:
$('#return').on('change', function () {
if ($(this).is(':checked')) {
$('#datepickerr').val('');
$('#altway').show();
} else {
$('#altway').hide();
}
});