简体   繁体   中英

jquery datepicker textbox value issue

I have 2 text boxes namely fromDate & toDate for date search , in which by default, current day will be showed.

working code:

Jquery

(document).ready(function () {
    $('.dateClass').datetimepicker({timepicker: false}); // css for displaying date without time

    $('#fromDateId').datetimepicker({value: '01-01-2016', format: 'd-M-Y'});     // display current date with dd-mmm-yyyy        
    $('#toDateId').datetimepicker({value: '01-01-2016', format: 'd-M-Y'});       // display current date with dd-mmm-yyyy  
});   

Struts

<html:text property="fromDate"  styleId="fromDateId" styleClass="dateClass"  />
<html:text property="toDate"  styleId="toDateId" styleClass="dateClass"  />

Issue:

By default current day shown in both textboxes, suppose user choose different dates and submit, db records are fetched and displayed but these 2 texboxes replaced with current dates how to avoid this.

kindly help me to resolve.

Update: There are reports this no longer works in Chrome.

This is concise and does the job:

$(".fromDateId").datepicker('setDate', new Date());

And another thing,

$(function()
{
    $('.date-pick').datePicker().val(new Date().asString()).trigger('change');
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM