lenamtl
asked on
Datepicker prepopulate with today date
Hi,
I'm using Jquery Datepicker http://docs.jquery.com/UI/Datepicker
in my form and I like to prepopulate the field with today date.
The calendar is preseleting the today date but the date field is empty by default.
Here is my code
//PHP code the value = empty
//js
//the form input
Thanks
I'm using Jquery Datepicker http://docs.jquery.com/UI/Datepicker
in my form and I like to prepopulate the field with today date.
The calendar is preseleting the today date but the date field is empty by default.
Here is my code
//PHP code the value = empty
$date = '';
//js
//date picker
$(document).ready(function(){
$("#dp").datepicker({
showOn: 'button',
buttonImage: 'img/calendar_20.png',
buttonImageOnly: true,
dateFormat: 'yy-mm-dd',
dayNamesMin: ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'],
monthNamesShort: ['Jan','Fev','Mar','Avr','Mai','Jui','Jul','Aou','Sep','Oct','Nov','Dec'],
firstDay: 1 ,
showButtonPanel: false,
changeMonth: true,
changeYear: true
});
});
//the form input
<tr>
<td>
Date yyyy-mm-dd:
</td>
<td>
<div>
<input type=text name=date size=10 id="dp" value="<?php echo $date; ?> ">
</div>
</td>
</tr>
Thanks
Also, beware of using the word "date" -- this is a reserved word in MySQL so it can trip you up. I have an article here about PHP and MySQL DATETIME processing. You may find it helpful.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
Best regards, ~Ray
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
Best regards, ~Ray
what is the CURRENT format of $date ? Y-m-d ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if the format is YYYY-MM-DD :
you can use and hidden field to get the php string date ;
you can use and hidden field to get the php string date ;
<tr>
<td>
Date yyyy-mm-dd:
</td>
<td>
<div>
<input type="hidden" name="hdate" size="10" id="hdp" value="<?php echo $date; ?>" />
<input type="text" name="date" size="10" id="dp" />
</div>
</td>
</tr>
@Ray_Paseur, thank you for the information. Did'nt see you last comment before posting.
So I finish to post :
So I finish to post :
$(document).ready(function(){
$("#dp").datepicker({
showOn: 'button',
buttonImage: 'img/calendar_20.png',
buttonImageOnly: true,
dateFormat: 'yy-mm-dd',
dayNamesMin: ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'],
monthNamesShort: ['Jan','Fev','Mar','Avr','Mai','Jui','Jul','Aou','Sep','Oct','Nov','Dec'],
firstDay: 1 ,
showButtonPanel: false,
changeMonth: true,
changeYear: true
});
var hdp = $("#hdp").val().split("-");
var dp_year = hpd[0];
var dp_month = hpd[1];
var dp_day = hpd[2];
$("#dp").datepicker("setDate", new Date(parseInt(dp_year), parseInt(dp_month)-1, parseInt(dp_day)));
});
@leakin971: Do you happen to know if the PHP date function can return information in location or language? (I don't) It might be nice for our asker if we could give back information in French.
>Do you happen to know if the PHP date function can return information in location or language?
No, I don't know.
>It might be nice for our asker if we could give back information in French.
It's not a good thing for further readers
No, I don't know.
>It might be nice for our asker if we could give back information in French.
It's not a good thing for further readers
ASKER
Thanks a lot
I have modified
$date = '';
to
$date = date('Y-m-d');
and it isworking perfectly
I have modified
$date = '';
to
$date = date('Y-m-d');
and it isworking perfectly
Thanks for the points. Please see this post. It is in Russian but the language translation concept might port easily to French.
http://us.php.net/manual/en/function.date.php#92090
Best regards, ~Ray
http://us.php.net/manual/en/function.date.php#92090
Best regards, ~Ray
In the PHP code,
$date = date('c');