开发者

jQuery - Outputting jquery results to a hidden form field

I was wondering how i could output the results from my jQuery to a hidden form field so i can then shove it into the database.

Im using the Calendar function found here - http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/index.html

Apparently the following code gets the array, but im not sure how to forward it to the hidden field.

$('.date-picker').dpGetSelected()

From what i can tell i want the dpGetSelected to run with when the following is triggered dpClosed

Its all a bit confusing to me.

Any he开发者_JS百科lp would be great.

Cheers,


Use something like

$("#myhiddenfieldId").val($('.date-picker').dpGetSelected());


You can bind to the 'dateSelected' event to update the hidden field automatically whenever a date is selected. Assuming your hidden field has a name of "date", then:

$('.date-picker').bind('dateSelected', function (e, selectedDate) {
    $('input[name="date"]').val(selectedDate);
});

Here is the relevant demo from the plugin's website: http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerListen.html


Update: To trigger the event immediately after binding so that the hidden field is correctly populated in page load:

$('.date-picker').bind('dateSelected', function (e, selectedDate) {
    $('input[name="date"]').val(selectedDate);
}).trigger('dateSelected', [$('.date-picker').dpGetSelected()]);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜