Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
349 views
in Technique[技术] by (71.8m points)

datepicker - Post form on select with JQuery Datepick

I have a calendar I display with only certain dates available and the rest disabled. I get all my dates and make up my calendar and it displays without problem

<script type="text/javascript">
    $(function() {
        $.post('/jreqlib', 
            { Action: 'GetDates',
            }, function(data) {

                var myNewDates = new Array;
                for (var x = 0; x < data['validPubDates'].length; x++) {
                    myNewDates.push(data['validPubDates'][x]);
                }
                var myValidDates = new Array;
                for (var x = 0; x<data['validPubDates'].length; x++) {
                    var theDate = data['validPubDates'][x];
                    myValidDates.push(theDate);
                }               
                $('#inlineDatepicker').datepick({
                    multiSelect: 999,
                    minDate : '-14d',
                    maxDate : '+2y',                        
                    onSelect : function (dateText, inst) {
                        //alert("Clicked');
                        //$("#FormId").click();
                        $(this).parent('form').submit();
                    },
                    onDate : getAllowed(myValidDates),
                }).datepick('setDate',myNewDates);
            }, 
        'json');            
    }); 
</script>

The issue is I want to submit the form (not via ajax) when a date is clicked. I found a bunch of posts but none of them seemed to work. If I un-comment that "alert" then I see the "clicked" message but neither the $("#FormId").click(); (yes the form has a id="FormId" in it) or $(this).parent('form').submit(); or the 2 or 3 other ways I found to do the form submit.

I'm getting there on the click, the alert will fire if un-commented, how come the form won't submit?

(BTW - I didn't post the getAllowed function as I didn't think it relevant but I will if needed)

TIA

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try giving the form an id and then calling submit via an jquery id selector:

<form id="myFormID">
...
$('#inlineDatepicker').datepick({
    multiSelect: 999,
    minDate : '-14d',
    maxDate : '+2y',                        
    onSelect : function (dateText, inst) {
        $('#myFormID').submit(); // <-- SUBMIT LIKE THIS
    },
    onDate : getAllowed(myValidDates),
}).datepick('setDate',myNewDates);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...