0

I wanted to assign daterangepicker value to a text box in order to store the new selected date to a database. Though i tried this but didn't work as i expected.

HTML

<input type="text" id="" name="docrcvd" value="<?php echo $res->doc_date; ?>" class="form-control col-md-12" disabled="disabled">
                               <input type="text" id="birthday1" class="fa fa-calendar date-picker "> 

This works fine and it populate the date stored in database and the second input filed display the datepicker.

But the problem is once i selected new date it won't assign the newly selected date to the first input field.

Jquery

$(document).ready(function() {
                      $('#birthday1').daterangepicker({
                            onSelect: function(dateText, inst) { 
                               $('#docrcvd').val(dateText);
                            }
                         });
                  });

Any help or suggestion would appreciated. Thank you!

j08691
  • 204,283
  • 31
  • 260
  • 272
Fekade
  • 17
  • 1
  • 4

1 Answers1

1

You are missing the ID for your input field.

<input type="text" id="" name="docrcvd" value="<?php echo $res->doc_date; ?>" class="form-control col-md-12" disabled="disabled">
                           <input type="text" id="birthday1" class="fa fa-calendar date-picker "> 

has to look like this

<input type="text" id="docrcvd" name="docrcvd" value="<?php echo $res->doc_date; ?>" class="form-control col-md-12" disabled="disabled">
                           <input type="text" id="birthday1" class="fa fa-calendar date-picker "> 

You are using the ID Selector '#elementId'

$('#docrcvd').val(dateText);

But you did not assign that id to your element so your code would never find your input field to fill it.

Nila
  • 49
  • 10
  • Thank you TeryX. I have done the changes as per your suggestions. But, still didn't update the first filed(ID="docrcvd"). Any other suggestion you might think of would be appreciated. Thank you again. – Fekade Jun 03 '17 at 16:00
  • To update the data stored in the database you have to notify the Server about the changes you made. A common way to do this is to create an ajax request https://www.w3schools.com/jquery/jquery_ajax_get_post.asp You then need to handle that on server-side with (probably in your case) an PHP file to write these changes to the database https://stackoverflow.com/questions/5004233/jquery-ajax-post-example-with-php may help you – Nila Jun 03 '17 at 16:31
  • Thank you Teryx and the issue is resolved as per your suggestion. – Fekade Jun 03 '17 at 16:34