简体   繁体   中英

Date Time Picker value in hidden field

I am using daterangepicker and created an asp.net webform with help of the following codes

 <script type="text/javascript"> $(function () { $('#calendar').datetimepicker({ format: 'L', inline: true }); }); </script>
 <div id="calendar" style="width: 100%"></div> <asp:HiddenField ID="HiddenField1" runat="server" />

I wanted to display selected date into asp.net Hidden Field

Try the below code.

 $(function() { $('#calendar').datetimepicker({ format: 'L', inline: true }); }); $("#calendar").on("dp.change", function (e) { alert(e.date); $('#HiddenField1').val(e.date); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/js/bootstrap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/css/bootstrap.min.css" /> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.css" /> <div id="calendar" style="width: 100%"></div> <asp:HiddenField ID="HiddenField1" runat="server" />

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