简体   繁体   中英

jQuery Submit Form onChange

I'm looking to automatically submit a form using jQuery when an input is changed.

The input in question is a date picker and I need it to submit once somebody has made a selection.

<form id="select_date" name="select_date" method="POST" action="about.php?date-yes">
<input type="text" id="widgetFieldInput">
<input name="select_date" type="submit" />
</form>

Any help would be amazing!

Use the following jQuery snippet:

$("#widgetFieldInput").change(function() {
     this.form.submit();
});
$(document).ready(function(){
   $('#widgetFieldInput').change(function(){
       $('#select_date').click();
    });
});

If you are using the datepicker from jquery-ui you can use the onSelect event to fire custom code once a date has been picked:

$('you-date-input').datepicker({
   onSelect: function(dateText, inst) { 
      // form submit code
   }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM