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
you defining
.datepicker()
function on.datepicker
class. , inshowpicker()
passing#datefrom1
, datepicker considers undefined.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
Post a Comment