开发者

Call jquery datepicker from link and send the date through a post call

I need to make the datepicker show when I click on a link and then send the selected date to a different page through a post call.

T tried to use this code for the link call:

$(".click-on-link").click(function(){
    $('#datepicker').datepicker({
        changeMonth: true,
        changeYear: true,
        dateFormat: 'dd/mm/yy',
        firstDay: 1
    });
});

and the html:

<a class="click-on-link" href="#">show datepicker</a>

but it's not work开发者_JAVA技巧ing. Any idea?

Thanks!


$(function() {
    $(".click-on-link").click(function() {
        $('#datepicker').datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'dd/mm/yy',
            firstDay: 1,
            onSelect: function(dateText, inst) {
                alert(dateText) // make your AJAX call!
            }
        }).focus(); //make the datepicker appear!
    });
});


I'd start off by first initialising your date picker when the page loads as follows:

$(document).ready(function() {
     // Date picker initialisation
     $("#datepicker").datepicker({
         showOn: 'button',
         buttonImage: 'images/button_cal.gif',
         buttonImageOnly: true,
         dateFormat: 'd MM yy',
         minDate: new Date(),
         onSelect: function(dateText, inst) {
                    // inst.selectedYear, selectedMonth and selectedDate hold the values you need. Use $.ajax() to send off to the server.
         }
     });

     // Show the date picker
         $(".class").click(function() {
         $("#datepicker").datepicker("show");
     });

});

Try the following sample, which lets you click on the text 'Date' which brings up the date picker for me. Perhaps we can work from this sample to get your scenario working:

<script type="text/javascript">
$(function() {
    $("#datepicker").datepicker({});

    $("#test").click(function(){
        $("#datepicker").datepicker('show');
    });
});
</script>

<p id="test">Date:</p> <input type="text" id="datepicker">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜