I have dynamic form, Now when Input generated, there is 2 datepicker (FromDate, ToDate), and you can generate many of this tow inputs.
The Input come like this:
<input type="text" class="input-date displayDate complexField" name="Course[FromDate][1]" value="" />
<input type="text" class="input-date displayDate complexField" name="Course[ToDate][1]" value="" />
Each Input will generate jQuery for datepicker like this:
$(document).ready(function() {
{/literal}$(".input-date").datepicker({literal}{
dateFormat: dFormat,
showOn: 'button',
changeMonth: true,
changeYear: true,
minDate: new Date(1940, 1 - 1, 1),
maxDate: '+10y',
yearRange: '-99:+99',
onSelect: function(selected) {
$("[name^='Course[FromDate]']").datepicker("option","maxDate", selected)});
$("[name^='Course[ToDate]']").datepicker("option","minDate", selected)});
}
});
Now everything work fine, you can add many these two inputs and all of them with datepicker.
The Only problem is:
The option onSelect work fine only if you have only the first element (FromDate and ToDate) the ToDate can't be greater than FromDate and vice versa,
But when I add other elemnts which will be:
<input type="text" class="input-date displayDate complexField" name="Course[FromDate][2]" value="" />
<input type="text" class="input-date displayDate complexField" name="Course[ToDate][2]" value="" />
The onSelect will work wrong, it will work 4 together, I need it work with elements with array index (1) alone, and in elements with index number (2) works alone and so on.
Please advice me on this ...
Use this code and try agin
$('document').ready(function(){
$('.input-date').on('click',function(){
$(this).datepicker({literal}{
dateFormat: dFormat,
showOn: 'button',
changeMonth: true,
changeYear: true,
minDate: new Date(1940, 1 - 1, 1),
maxDate: '+10y',
yearRange: '-99:+99',
onSelect: function(selected) {
$("[name^='Course[FromDate]']").datepicker("option","maxDate", selected)});
$("[name^='Course[ToDate]']").datepicker("option","minDate", selected)});
}
});
});
Related
I'm a newbie in this php and html. I'm developing a laundry system using php with mysql. right now, users can just enter whatever date they want for pickup and delivery.. for example, today is 10 feb 2018, user key in 9 feb 2018 as pickup. that should not be possible. how do i handle that? my html are
<font face="Arial Black">Pickup date:</font>
<input type="date" name="pickupdate">
The below snippet is from one of my projects, see if this helps you in anyway:
The HTML Code:
<label for="from">From</label>
<input type="text" id="from" name="from"/>
<label for="to">to</label>
<input type="text" id="to" name="to"/>
The Javascript Code:
var dateToday = new Date();
var dates = $("#from, #to").datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
minDate: dateToday,
onSelect: function(selectedDate) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $(this).data("datepicker"),
date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
dates.not(this).datepicker("option", option, date);
}
});
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:'
});
});
can't find solution to this issue. So i have datepicker input field, it works fine, i can choose date and save it to database. But when i want to edit this saved value in edit_profile.php this field is empty, i need to see the user specified date. How to do it?
Datepicker function:
$(function() {
$( "#datepicker" ).datepicker({
dateFormat: "yy-mm-dd",
changeMonth: true,
changeYear: true
}).val('<?php echo $age;?>');
});
Input:
<input name="datepicker" type="text" id="datepicker" class="date_picker" value="" />
what to do ?
Can't you just do this:-
<input name="datepicker" type="text" id="datepicker" class="date_picker" value="<?php echo $age;?>" >
I think you should use defaultDate option, for example
$( "#datepicker" ).datepicker({ dateFormat: "yy-mm-dd", changeMonth: true, changeYear: true, defaultDate: yourDate });
You can use SetDate or Defaultdate option of datepicker:
$('#dateselector').datepicker("setDate", new Date(2008,9,03) );
When i set my input field without datepicker like that:
<input type="text" name="date" value="<?php echo $date; ?>" class="textbox" />
I can see my value which i get from database. The format is: 1965-02-05
When I set this code:
<script>
$(function() {
$( "#datepicker" ).datepicker({
changeMonth: true,
changeYear: true
}
);
$( "#datepicker" ).datepicker( "option", "dateFormat", "yy-mm-dd" );
$( "#datepicker" ).datepicker( "option", "yearRange", '1900:2011' );
});
</script>
<input type="text" id="datepicker" name="date" value="<?php echo $date; ?>" class="textbox" />
nothing shown in text input area, but i can see datepicker without any problem when i click inside of the text input area.
What is the problem?
I'am formatting like that:
http://docs.jquery.com/UI/Datepicker/formatDate
$( "#datepicker" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'yy-mm-dd',
yearRange: '1900:2011',
constrainInput: false
});
See working example: http://jsfiddle.net/eATRv/
Try this. Now you should also be able to see if it is the correct format :)
$(function() {
$(".datepicker").datepicker({
dateFormat: 'mm-dd-yy',
yearRange: 'c-70:c+10',
changeYear: true,
changeMonth: true,
numberOfMonths: 3,
showWeek: true,
firstDay: 1,
showOn: 'button',
buttonImage: "/images/scw.gif"; ?>',
buttonImageOnly: true
});
});
<input type='text' name='from_date' id='from_date' class='datepicker'>
<input type='text' name='to_date' id='to_date' class='datepicker'>
I was able to reproduce this with a recent version of jQuery with a date format of
{
dateFormat: 'mm-dd-yyyy'
}
Consider yy to be a full 4 digits year.
Edit: Is this the only instance of .datepicker invocation in your script? Are there any calls? Is this using a custom locale thats not en? Do you have a link?
Are you sure its not yyyy instead of yy?
I had the same issue, it was because I called jQuery().datepicker() twice.