Datepicker Submit form when select date

2019-01-28 20:58发布

问题:

please help me, how can i edit my javascript to submit form after select a date

     Date: <div id="datepicker"></div>


    <form action='?data=$data' method='POST' enctype='multipart/form-data'></form>

        <script>
      $(function() {
        $( '#datepicker' ).datepicker( $.datepicker.regional[ 'it' ] );
        $( '#locale' ).change(function() {
        $( '#datepicker' ).datepicker( 'option',
        $.datepicker.regional[ $( this ).val() ] );

    });

  });
 </script>

回答1:

I found solution. You may rewrite code like this.

<form method='POST' enctype='multipart/form-data' id='formId'>
  <input type="text" id="datepicker"/>
</form>

$(document).ready(function() {
  $('#datepicker').datepicker({
       onSelect : function (dateText, inst) {
          $('#formId').submit(); // <-- SUBMIT
  }});
});

This code from another post