Inline date picker not working using jquery/html - javascript

I am using jquery to create an inline date picker but the entire date picker is only displayed. It does not even change months. I want it to display the date when calendar day is clicked.
The datepicker should display the date when clicked but no changes are shown in the input field. I searched for the same on stackover but no luck.
<link href="https://fonts.googleapis.com/css?family=Lobster"
rel="stylesheet" type="text/css">
<link rel="stylesheet" href="style.css">
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-
awesome.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-
ui.min.js"></script>
<div>
<div class="ids" id="1" style="float:left; clear:both">
<b style="color: #444444">Date</b>
<input id="enterdate" class="duedatetextbox" data-inline = "true" type="text" placeholder="Enter date" tabindex="101" disabled>
<div id= "setdate" style = "margin-left:0px;">
</div>
</div>
<div class="ids" id="2" style="float:left;">
<b style="color: #444444">Time</b>
<input class="duedatetextbox" type="text" placeholder="Enter time" tabindex="102">
</div>
</div>
Jquery:
<script type ="text/javascript">
//date picker
$('#setdate').datepicker({
inline: true,
altField: '#d'
});
$('#enterdate').change(function(){
$('#setdate').datepicker('setDate', $(this).val());
});
function adddescription()
{
$(`.description`).show();
$('.cardgutterrow').hide();
}
</script>
CSS
div.ids {
width: 50%;
}
div.ids b {
display: block;
}
div.ids input {
display: block;
padding: 10px;
background: whitesmoke;
border: solid 1px grey;
border-radius: 3px;
}
JSFiddle Here

$('#setdate').datepicker({
inline: true,
altField: '#d',
onSelect: onDateChange
});
function onDateChange(dateText, inst)
{
$("#enterdate").val(dateText);
}
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="style.css">
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<div>
<div class="ids" id="1" style="float:left; clear:both">
<b style="color: #444444">Date</b>
<input id="enterdate" class="duedatetextbox" data-inline = "true" type="text" placeholder="Enter date" tabindex="101" disabled>
<div id= "setdate" style = "margin-left:0px;">
</div>
</div>
<div class="ids" id="2" style="float:left;">
<b style="color: #444444">Time</b>
<input class="duedatetextbox" type="text" placeholder="Enter time" tabindex="102">
</div>
</div>

You have not initialized the date-picker correctly. I have removed some extra piece of code and added jquery-ui.min.css for proper styling of calendar
HTML-
<input type="text" id="datepicker">
Script-
$( function() {
$( "#datepicker" ).datepicker();
});
Updated fiddle - https://jsfiddle.net/q1fwaevL/2/
You can refer api docs of jquery calendar here for other datepicker events- http://api.jqueryui.com/datepicker/

Related

Uncaught TypeError: jQuery(...).datetimepicker is not a function

I have a code to generate a normal date time picker, but it is throwing me this error Uncaught TypeError: jQuery(...).datetimepicker is not a function
Can anyone help me, i guess it is because of arrangment of links and bootstrap , but i don't have a clear picture of it.
below is my code
<html>
<head>
<link rel="stylesheet" href="jquery.datetimepicker.css">
<script src="jquery-1.8.2.min.js"></script>
<!-- <script src="jquery-ui.js"></script> -->
<script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script>
<script src="jquery.datetimepicker.js"></script>
<script src="jquery.validate.min.js"></script>
<link rel="stylesheet" href="fonts/icomoon/style.css">
<link rel="stylesheet" href="css/owl.carousel.min.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css">
<script>
$(document).ready(function() {
jQuery('#datevalue').datetimepicker();
jQuery('#completed').datetimepicker();
});
</script>
</head>
<body>
<form action="#" method="post">
<div id="AlignMainDiv">
<div class="form-group last mb-4">
<label for="date">Date</label>
<input type="text" class="form-control" id="datevalue">
</div>
<div class="form-group last mb-4">
<label for="username">Completed Date and Time</label>
<input type="text" class="form-control" id="completed">
</div>
</div>
</form>
</body>
</html>
Press F11, open the Chrome debug, go to Network > JS tab and check if any of the included js libraries return a 404 status. Maybe you misspelled a script name or URL path.
You can also try to include the libraries directly from CDNs:
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.13.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script>
<script>
$( function() {
$('#datevalue').datetimepicker();
$('#completed').datetimepicker();
} );
</script>
</head>
I dont know whether your datetimepicker library is loading or not.
You can use following CDN.
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.4/build/jquery.datetimepicker.full.min.js"></script>
Following code will load todays date and will show datepicker on input click
<script>
$(document).on("click", "#datevalue" , function() {
$(this).datetimepicker({
timepicker:false, format:"d-m-Y","setDate": new Date(),
}).focus();
});
</script>

Displaying double date picker

Hi Stackoverflow comunity!
I'm really new using fullcalendar, Js and the datetime-picker. I'm adding into a date picker, the selected date by fullCalendar.
So for doing that here is my code piker in HTML
select: function(inform) {
var date_from= new Date(inform.startStr);
var date_to= new Date(inform.endStr) ;
let currentDate = new Date();
if (date_from >= currentDate) {
$('#exampleModalToggle').modal('show');
$(".fc-highlight").css("background", "#ffc800", "important!");
$(function() {
$("#start_date_picker").datepicker({
dateFormat: "yy-mm-dd",
}).datepicker("setDate", date_from);
$("#end_date_picker").datepicker({
dateFormat: "yy-mm-dd"
}).datepicker("setDate", date_to);
});
} else if( date_to < currentDate ){
console.log(' date clicked lower than current date, you can NOT do reservation')
}
},
<meta charset='utf-8' >
<meta http-equiv="x-ua-compatible" content="ie=edge">
<!--bootstrap 5-->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous"/>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4"
crossorigin="anonymous"></script>
<!--date time picker css-->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css" />
<!-- responsive -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<!-- fontawsome -->
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css"
integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous" />
<!-- fonts-->
<link href="https://fonts.cdnfonts.com/css/nexa-bold" rel="stylesheet"/>
<!--Start Date-->
<div id="start_date" class="add_reservation_subtitles pb-3" style="margin-left: 28px;">
<input id="start_date_input" data-provide="datepicker" name="start_date" type="date"
lang="fr" id="datepicker_second" class="datepicker1" style="margin-left: 28px;" required>
<input name="start_hour" type="time" lang="fr" class="timepicker modal_rigth_elements"
required>
</div>
<!--End Date-->
<div id="end_date" style="margin-left: 28px;" class="add_reservation_subtitles pb-3 ">
<input id="end_date_input" type="date" lang="fr" class="date-picker"
style="margin-left: 28px;" required>
<input name="end_hour" type="time" lang="fr" class="timepicker modal_rigth_elements"
required>
</div>
<script src="{% static 'jquery-3.6.0.js' %}"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.1/dist/umd/popper.min.js"
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"
integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js#3.3.0/dist/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fullcalendar#5.7.0/main.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fullcalendar#5.7.0/locales-all.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"
integrity="sha512-qTXRIMyZIFb8iQcfjXWCO8+M5Tbc38Qi5WzdPOYZHIlZpzBHG3L3by84BBBOiRGiEb7KKtAOAs5qYdUiZiQNNQ=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
The problem is that I'm having two calendars being displayed. The second one appears just after closing the first one.
I guess is about setting the HTML type as date and for instantiating the calendar using the JS datepicker.
So I would like to know how to avoid this behaviour without affecting the display of calendar.

daterangepicker is not a function javascript

I got an error when trying to create daterangepicker, I did exactly as instructed on https://www.daterangepicker.com, but it didn't work. What this erro? How to fix this erro? I have just started learning js recently, please can you give me a detailed guide. Thanks
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />
<link href="static/html/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="static/plugins/bower_components/sidebar-nav/dist/sidebar-nav.min.css" rel="stylesheet">
<link href="static/html/css/animate.css" rel="stylesheet">
<link href="static/html/css/style.css" rel="stylesheet">
<link href="static/html/css/colors/default.css" id="theme" rel="stylesheet">
<script type="text/javascript" src="http://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
<script>
$(function() {
$('input[name="date_times"]').daterangepicker({
timePicker: true,
startDate: moment().startOf('hour'),
endDate: moment().startOf('hour').add(32, 'hour'),
locale: {
format: 'MM/DD/YYYY HH:mm'
}
});
});
</script>
<script>
function submitDate() {
document.getElementById("frm1").submit();
}
</script>
<style>
div.set_height {
height: 100px;
}
</style>
</head>
<body class="fix-header">
<div class="row">
<div class="col-sm-12">
<div class="col-sm-7 white-box set_height">
<h3 class="box-title">Historical Table</h3>
<p class="text-muted"> Data will be saved every 30 minutes</p>
</div>
<div class="col-sm-5 white-box set_height">
<form id="frm1" method=POST action="{{ url_for('get_history') }}">
<h3 class="box-title"> Filter :
<input type="text" placeholder="M/D/Y H:m - M/D/Y H:m" name="date_times"/>
<button type="submit" onclick="submitDate()" style=background-color:#e7e7e7;color:blue;>Submit</button>
</h3>
</form>
<p class="text-muted">Select date and time</p>
</div>
</div>
</div>
<footer class="footer text-center"> © Dashboard Pepple Counting </footer>
<script src="static/plugins/bower_components/jquery/dist/jquery.min.js"></script>
<script src="static/html/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="static/plugins/bower_components/sidebar-nav/dist/sidebar-nav.min.js"></script>
<script src="static/html/js/jquery.slimscroll.js"></script>
<script src="static/html/js/waves.js"></script>
<script src="static/html/js/custom.min.js"></script>
</body>
</html>

How to add Timepicker in a Datepicker in jsp page using javascript

I have a date picker in my JSP page. Now I want to add start time and end time with in this datepicker i.e calender. How to do that. I also want to set validation that start time should always be less than the end time. My code for datepicker in JSP is
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>User_Interface</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$("#datepicker").datepicker({ minDate: -210, maxDate: -1 });
});
</script>
</head>
<b>Select Date to be compared</b><br>
<p>Date: <input type="text" name="datepicker" id="datepicker"></p>
<input type="submit" value="Submit"><br>
EDIT
Now my datepicker i.e. calender is also not working when I tried with this code
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>User_Interface</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<link type="text/css" href="css/bootstrap.min.css" />
<link type="text/css" href="css/bootstrap-timepicker.min.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap-2.2.2.min.js"></script>
<script type="text/javascript" src="js/bootstrap-timepicker.min.js"></script>
<script>
$(function() {
$("#datepicker").datepicker({ minDate: -210, maxDate: -1 });
});
</script>
<script type="text/javascript">
$('#timepicker2').timepicker({
minuteStep: 1,
template: 'modal',
appendWidgetTo: 'body',
showSeconds: true,
showMeridian: false,
defaultTime: false
});
</script>
</head>
<body>
<br>
<br>
<form>
<b>Select Date to be compared</b><br>
<p>Date: <input type="text" name="datepicker" id="datepicker"></p>
<div class="input-append bootstrap-timepicker">
<input id="timepicker2" type="text" class="input-small">
<span class="add-on">
<i class="icon-time"></i>
</span>
</div>
<input type="submit" value="Submit">
<br>
</form>
</body>
</html>
Can anyone please help me with this.
try by changing the type in input tag from
type="text"
to
type="datetime-local"
and start modifying accordingly
Change to a datetimepicker. There are several around.
I use this one.
You can use this Jquery Plugin which will add timepicker functionality to your input elements.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" href="css/bootstrap.min.css" />
<link type="text/css" href="css/bootstrap-timepicker.min.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap-2.2.2.min.js"></script>
<script type="text/javascript" src="js/bootstrap-timepicker.min.js"></script>
</head>
<body>
<div class="input-append bootstrap-timepicker">
<input id="timepicker1" type="text" class="input-small">
<span class="add-on"><i class="icon-time"></i></span>
</div>
<script type="text/javascript">
$('#timepicker1').timepicker();
</script>
</body>
</html>
Works for me.
Hope this helps.

Error: Object doesn't support property or method 'datetimepicker'.. Can't seem to create a datepicker

Always getting an error whenever I try to create a datepicker in my form. Can anyone help me out? I believed I have referenced the proper CSS, JS, Bootstrap and JQuery files.
<script src="js/jquery-2.1.1.js"></script>
<link href="css/animate.min.css" rel="stylesheet" />
<link href="css/bootstrap.css" rel="stylesheet" />
<link href="css/color2.css" rel="stylesheet" />
<link href="css/font-awesome.min.css" rel="stylesheet" />
<link href="css/font_google.css" rel="stylesheet" />
<link href="css/style.css" rel="stylesheet" />
<link href="css/bootstrapValidator.css" rel="stylesheet" />
<link href="css/bootstrapValidator.min.css" rel="stylesheet" />
<script src="js/bootstrapValidator.js"></script>
<script src="js/bootstrapValidator.min.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/PageValidator.js"></script>
<script src="js/Validator2.js"></script>
<link href="css/datepicker.css" rel="stylesheet" />
<script src="js/bootstrap-datepicker.js"></script>
here's my attempt at creating a datepicker
<div class="form-group">
<label for="Birthday">Birth Date</label>
<div class="input-group">
<span class="input-group-addon flat">
<span class=" glyphicon glyphicon-calendar"></span>
</span>
<div class="input-group date" id="dobPicker" data-date-format="MM/DD/YYYY">
<input type="text" class="form-control" id="birthday" name="birthday" placeholder="MM/DD/YYYY"
data-bv-notempty="true" data-bv-notempty-message="Birth Date is required and cannot be empty"
data-date-format="MM/DD/YYYY" data-bv-date-message="Invalid Date" />
</div>
</div>
</div>
<script type="text/javascript">
$(function () {
$('#birthday').datetimepicker({
pickTime: false
});
});
</script>
Any insight (and possibly a code fix) would be greatly appreciated!!
I know i am 2 years late to the party, but i just had the problem and found 'a' solution that might help someone in the future.
I got an error of undefined method because i loaded the wrong .js file out of the bundle.
I loaded jquery.datetimepicker.min.js out of the root dir from the package instead of jquery.datetimepicker.full.min.js out of the build folder.
If its bootstrap date Time picker use the following code :
$(function () {
$('#birthday').datepicker()({
pickTime: false
});
});
Fiddle : http://jsfiddle.net/QD94K/1/
I had the same problem. In my case I fixed it by adding:
<script src="Scripts/jquery-ui-1.10.4.js"></script>
Assuming you're using this datepicker, you should select the containing div instead of the input element.
$(function () {
$('#dobPicker').datetimepicker({
pickTime: false
});
});
You have to add - jquery_calendar/jquery-ui.js
<script type="text/javascript" src="Scripts/jquery_calendar/jquery-ui.js"></script>
or
<script src="Scripts/jquery-ui-1.10.4.js"></script>
then add JQuery code
$(document).ready(function () {
$('.openCalendar').datepicker({
closeText: "Select",
changeMonth: true,
changeYear: true
});});
if Jquery Ui is not there Calander will not works.

Categories

Resources