At the moment, I am using the datepicker jquery ui widget to allow users to pick a date off the calendar.
I want to change what I have so I can have the calendar appear on hover/ click of text saying 'choose your day' and then when the calendar option is clicked, it will redirect to a page.
Is this possible?
Jquery at the moment -
<script>
$(function() {
$( "#datepicker" ).datepicker({ dateFormat: 'yy-mm-dd' });
$('#datepicker').datepicker('setDate', 'today');
});
</script>
Html
<input type="text" id="datepicker" size="30" name="date"/>
Cheers
1.
and then when the calendar option is clicked, it will redirect to a
page.
http://api.jqueryui.com/datepicker/#option-onSelect
$( "#datepicker" ).datepicker({
dateFormat: 'yy-mm-dd',
onSelect: function(){
document.location.href = '/';
}
});
2.
I can have the calendar appear on hover/ click of text saying 'choose
your day'
$('#datepicker').on('focus', function(){
alert('Choose your date');
});
Related
Am using Jquery Datepicker for my project . If i want to change date format my code will be
$( "#datepicker1" ).datepicker({
dateFormat: "dd-mm-yy"
});
Its not working . But if am using this format its working
$("#datepicker1").datepicker("setDate", '+1d');
Please provide me a solution . Thanks in Advance
To disable all previous dates, give start date as today date
startDate: new Date()
$(function() {
$( "#datepicker" ).datepicker({
format: 'dd/mm/yyyy',
startDate: new 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/datepicker/0.6.5/datepicker.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/datepicker/0.6.5/datepicker.min.css" rel="stylesheet"/>
<div> Select Date <input type="text" id="datepicker" /></div>
I'm working with php and datepicker for an application that requires the week number from a date. I just noticed that datepicker is one week behind php date("W"). I have a Fiddle showing the issue. Is there a way to correct this? Thanks for any insight.
JS:
<script>
$(document).ready(function () {
$( ".datepicker" ).datepicker({
showWeek: true,
dateFormat: 'yy-mm-dd'
});
});
</script>
PHP:
<?php echo 'Current week ' .date("W");?>
HTML:
<input name="date_task[]" class="datepicker" type="text" />
I was able to fix it by changing the first day of the week to monday.
<script>
$(document).ready(function () {
$( ".datepicker" ).datepicker({
showWeek: true,
dateFormat: 'yy-mm-dd',
firstDay: 1
});
});
</script>
basically I have a large form created on my WordPress site using Gravity Forms. One section of my forms has a bunch of items listed with a 'Start Date' followed by an 'End Date' -- Example:
Item | Start Date | End Date
Item#1 | 05/01/2015 | 05/25/2015
What I am after is making it so I can disallow the 'End Date' from being before the selected 'Start Date'. It would be best if the user was unable to even select the date from the date picker drop down, but if it has to be an error that pops up on submission, that is fine to. I have been researching this for hours and I am just too noob to know exactly what to do. Thanks for any and all help!
Try something like this, which uses jQuery's datepicker functions:
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="https://jqueryui.com/resources/demos/style.css">
<script>
$(function() {
$( "#from" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onClose: function( selectedDate ) {
$( "#to" ).datepicker( "option", "minDate", selectedDate );
}
});
$( "#to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onClose: function( selectedDate ) {
$( "#from" ).datepicker( "option", "maxDate", selectedDate );
}
});
});
</script>
<label for="from">From</label>
<input type="text" id="from" name="from">
<label for="to">to</label>
<input type="text" id="to" name="to">
When i submitted form than if error occurred than value is not set in datepicker which is selected before. Datepicker field empty . how this possible ??
<html>
<head>
<script type="text/javascript" >.
$(function() {
$( "#dob" ).datepicker({
changeMonth: true,
changeYear: true,
yearRange: '1900:'
});
$( "#dob" ).datepicker( "option", "dateFormat", "dd-mm-yy" );
});
</script>
</head>
<body>
<form>
<input type="text" name="dob" id="dob" value="<?php if(isset($_SESSION['dob'])) echo $_SESSION['dob']; ?>" placeholder="Please enter date of birth" required/>
</form>
<body>
</html>
There can be many reasons for this issue.
Either the dob variable is null/empty/undefined.
The dob value is not in the correct format.
You have not used defaultDate in the datepicker.
For 1st part, you can only log and debug what is wrong.
For 2nd part, you can format the value in correct format. Search on SO for formatting a string to Date.
For the 3rd part:
$(function () {
$("#dob").datepicker({
defaultDate: $(this).val(), //Add this
dateFormat: 'dd-mm-yy', // And this too
changeMonth: true,
changeYear: true,
yearRange: '1900:'
});
});
I create a textbox and add a Jquery UI datepicker.But when I select and click the button.the textbox doesnt get post and show an error message like(Notice: Undefined index: date_text in C:....................\file.php on line 57 ).But when I enter a date using keyboard without having a datepicker it will submit well.Please help me.How can I do this having datepicker
this is my jquery code
<script>
$(function() {
$( "#datepicker" ).datepicker();
$( "#datepicker" ).datepicker( "option", "dateFormat", "yy-mm-dd" );
});
</script>
this is my textfield
<div id="datetobe">Date to be dispose
<label for="date_to_dispose"> <input name="datepicker" type="text" id="datepicker" class="textfield" /></label>
</div>
You have to set the callback function for the datepicker.
http://jqueryui.com/demos/datepicker/
Events tab, onSelect event. RTM.
$('#datepicker').datepicker({
format: 'whatever',
onSelect: function(dateText, inst) { ... }
});