jset_expert
asked on
jQuery Date picker problem
Hi, I have the successfully implemented the jQuery date picker into my PHP site.
I have drop-down lists for, date , month and year.
I grabbed some code of this site, http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerIntoSelects.html
The problem is the dates only go back to 2005. I am using this for birthday, so it needs to go back to 1900
I have updated my list for years like so;
<select name="y" id="y" style="width: 60px">
<?php
for ( $counter = 2008; $counter >= 1900; $counter -= 1) {
echo "<option value='$counter'>$counter< /option>";
}
?>
</select>
I have tried to edit the following code but with no success, (I changed the 2005 dates to 1900)
The year it now posts is completely out of whack!
Can anyone help me out.
I have drop-down lists for, date , month and year.
I grabbed some code of this site, http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerIntoSelects.html
The problem is the dates only go back to 2005. I am using this for birthday, so it needs to go back to 1900
I have updated my list for years like so;
<select name="y" id="y" style="width: 60px">
<?php
for ( $counter = 2008; $counter >= 1900; $counter -= 1) {
echo "<option value='$counter'>$counter<
}
?>
</select>
I have tried to edit the following code but with no success, (I changed the 2005 dates to 1900)
The year it now posts is completely out of whack!
Can anyone help me out.
<!-- date picker script -->
<script type="text/javascript" charset="utf-8">
$(function()
{
// initialise the "Select date" link
$('#date-pick')
.datePicker(
// associate the link with a date picker
{
createButton:false,
startDate:'01/01/1900',
endDate:'31/12/2008'
}
).bind(
// when the link is clicked display the date picker
'click',
function()
{
updateSelects($(this).dpGetSelected()[0]);
$(this).dpDisplay();
return false;
}
).bind(
// when a date is selected update the SELECTs
'dateSelected',
function(e, selectedDate, $td, state)
{
updateSelects(selectedDate);
}
).bind(
'dpClosed',
function(e, selected)
{
updateSelects(selected[0]);
}
);
var updateSelects = function (selectedDate)
{
selectedDate = new Date(selectedDate);
var d = selectedDate.getDate();
var m = selectedDate.getMonth();
var y = selectedDate.getFullYear();
($('#d')[0]).selectedIndex = d - 1;
($('#m')[0]).selectedIndex = m;
($('#y')[0]).selectedIndex = y - 1900;
}
// listen for when the selects are changed and update the picker
$('#d, #m, #y')
.bind(
'change',
function()
{
var d = new Date(
$('#y').val(),
$('#m').val()-1,
$('#d').val()
);
$('#date-pick').dpSetSelected(d.asString());
}
);
// default the position of the selects to today
var today = new Date();
($('#d')[0]).selectedIndex = today.getDate() - 1;
($('#m')[0]).selectedIndex = today.getMonth();
($('#y')[0]).selectedIndex = today.getFullYear() - 1900;
// and update the datePicker to reflect it...
$('#d').trigger('change');
});
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.