user580523
user580523

Reputation:

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!

Upvotes: 13

Views: 50756

Answers (3)

Ritik Khatwani
Ritik Khatwani

Reputation: 549

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

Upvotes: 15

NakedBrunch
NakedBrunch

Reputation: 49413

Use the following jQuery snippet:

$("#widgetFieldInput").change(function() {
     this.form.submit();
});

Upvotes: 22

Bj&#246;rn
Bj&#246;rn

Reputation: 2648

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
   }
});

Upvotes: 4

Related Questions