javascript - Jquery Cannot get datepicker value -


on code:

<input type="text" id="datefrom1" name="datefrom1" class="form-control datepicker"/>             <i class="ace-icon1 fa fa-calendar"/>  <script type="text/javascript">     $('.datepicker').datepicker(); </script> 

when submit form, params.datefrom1 hold value of datepicker. however, when used way, cannot value of datepicker

<input type="text" id="datefrom1" name="datefrom1" class="form-control datepicker" disabled/>             <i class="ace-icon1 fa fa-calendar" onclick="showpicker('#datefrom1')"/> <script type="text/javascript">     $('.datepicker').datepicker();      function showpicker(ele) {         $(ele).datepicker('show');     } </script> 

the fact input box shows value after picked date, , when alert($('#datefrom1')) alerted value of date when submit form, null value

working demo

  1. you defining .datepicker() function on .datepicker class. , in showpicker() passing #datefrom1, datepicker considers undefined.

  2. also, wrap datepicker initialisation code in $(document).ready(..)


html :

<input type="text" id="datefrom1" name="datefrom1" class="form-control datepicker" disabled/> <i class="ace-icon1 fa fa-calendar" onclick="showpicker('.datepicker')">icon</i> 

js :

$(document).ready(function(){      $('.datepicker').datepicker(); }); function showpicker(ele) {     $(ele).datepicker('show'); } 

suggestion : also, if using jquery, suggest use jquery .click() instead of inline onclick=".."


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -