-1

I have a text box bound to a date picker:

<!-- editExamScheduleModal -->
<div class="form-group">
    <label class="col-md-4 control-label" for="textExamDate">Exam Date</label>
    <div class="col-md-4">
        <input id="textExamDate" name="textExamDate" type="text" class="form-control input-md">
    </div>
</div>

This Div is shown as a pop-up and the function that assigns the values to the text box is like so:

function ShowPopup(examDateToEdit) {
    $('#textExamDate').val(examDateToEdit);
    $('#textExamDate').datepicker({ minDate: 0 });
    $('#editExamScheduleModal').modal('show');

    var expectedExamDate = new Date();
    var numberOfDaysToAdd = 1;
    expectedExamDate.setDate(expectedExamDate.getDate() + numberOfDaysToAdd);
    $('#textExamDate').datepicker("setDate", expectedExamDate);
}

In the above function I am trying to set the DatePicker to select the next day from the current day or whatever date is passed in examDateToEdit. It's ok if nothing comes in to the function, the date picker will default to current date.

Two things are happening:

  1. The DatePicker does show the expected date
  2. It's also putting in the date value in the text box

So if today's date is 01/21/2016 it puts 01/22/2016 in the text box.

The value in this text box is optional, meaning the user can leave it empty. But in my implementation shown above there will be a value in it and when the user hits Save, not shown here, they will unintentionally send a value back to server.

So what do I do to make only #1 happen?

Thanks in advance.

Regards.

Codehelp
  • 4,157
  • 9
  • 59
  • 96
  • Possible duplicate of [How do I clear/reset the selected dates on the jQuery UI Datepicker calendar?](http://stackoverflow.com/questions/9435086/how-do-i-clear-reset-the-selected-dates-on-the-jquery-ui-datepicker-calendar) – JotaBe Jan 21 '16 at 10:10

2 Answers2

0

This will be fixed by the below code

<script>
function ShowPopup(examDateToEdit) {
    if ((typeof examDateToEdit != "undefined") && examDateToEdit!="") {
       $('#editExamScheduleModal').modal('show');
       var numberOfDaysToAdd = 0;
    }
    else {
      var examDateToEdit = new Date();
      var numberOfDaysToAdd = 1;
    }

    examDateToEdit.setDate(examDateToEdit.getDate() + numberOfDaysToAdd);
    $('#textExamDate').datepicker("setDate", examDateToEdit); 
}
</script>
Thanga
  • 7,811
  • 3
  • 19
  • 38
0

there is one smart solution which i used $('#textboxid').val(''); after datepicker function call will make textbox empty.

Manish
  • 29
  • 3