I am trying to get the jQuery UI datepicker to submit a form when I click on one of the days in the datepicker.
I can get the datepicker to appear as expected and, if I click on the explicit submit button I have added the post method gets called. However I can't get onSelect to submit the form. I seem to be doing what is described in examples I can find on Google.
Can anyone here see the (probably obvious) error?
The javascript code in the headers is:-
jQuery(function() { jQuery( "#xvpicker" ).datepicker({ onSelect: function (dateText, inst) { jQuery(this).parent('form').submit(); alert("onSelect()");}, dateFormat: "dd/mm/yy"}); });
... and the HTML form is:-
<FORM METHOD=post ACTION="form.php" ID="xyzform" accept-charset="utf-8" enctype="multipart/form-data" >
<p>Date: <input type="text" name="xvdate" id="xvpicker"><input type="submit" name="xvsubm"></p>
</FORM>
Oh, and the alert message *does* pop up when I click on a day in the date picker. So the onSelect: code is executing, it's just that the submit() call doesn't seem to be submitting the form. I have tried using the form ID instead, i.e. jQuery('#xyzform').submit() but this doesn't work either.
On 10 October 2012 23:53, Chris Green cl@isbd.net wrote:
I am trying to get the jQuery UI datepicker to submit a form when I click on one of the days in the datepicker.
...
Can anyone here see the (probably obvious) error?
The javascript code in the headers is:-
jQuery(function() { jQuery( "#xvpicker" ).datepicker({ onSelect: function (dateText, inst) { jQuery(this).parent('form').submit(); alert("onSelect()");},
^^^ This line looks suspicious to me ^^^
It's not obvious to me what jQuery(this).parent('form') would return at this point - for that reason, I'd use simply the following ...
jQuery(document).ready(function () { jQuery( "#xvpicker" ).datepicker({ onSelect: function (dateText, inst) { jQuery("#xyzform").submit(); }, dateFormat: "dd/mm/yy" }); });
which works fine for me. In which case, your problem may be that you're not wrapping the function in a .ready() function.
HTH,
Greg