I need to trigger a form submit event when any form value changes and all the fields in the form are filled. Everything in this works apart from the $('#date_filter_form').submit();
line. I can .hide() the form but can't submit() it for some reason. Documentation says submit() is the same as trigger('submit') so I can't figure out why it wouldn't be working.
$('#date_filter_form input[type="text"]').change(function() {
var from_val = $('#date_filter_form #from_date').val();
var to_val = $('#date_filter_form #to_date').val();
if(from_val != '' && to_val != '') {
$('#date_filter_form').submit();
}
});
HTML:
<form method="post" id="date_filter_form" name="date_filter_form" action="">
<label class="left required" for="from_date">From</label>
<input type="text" id="from_date" class="datepicker hasDatepicker" value="" name="from_date">
<label class="left required" for="to_date">to</label>
<input type="text" id="to_date" class="datepicker hasDatepicker" value="" name="to_date">
<input type="hidden" value="" name="from_date_db">
<input type="hidden" value="" name="to_date_db">
<input type="submit" id="submit" class="button" value="Show results" name="submit">
</form>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…