Adding date to multiple fields via datepicker
- by Andy
i have a form in drupal with jquery based date module. there are multiple fields with date picker enabled. i want to set the value of all of them (they all have class .date-popup-init) to the value of the first field (#edit-field, the 'from' date) when that field is set.
my code so far:
<script type="text/javascript">
var DatePicked = function() {
var firstdate = $("#edit-field");
var updater = firstdate.datepicker("getDate");
$(".date-popup-init").each(function(){
$(this).datepicker("setDate", updater);
});
}
$(function() {
$("#edit-field").datepicker({
onSelect: DatePicked
});
});
</script>
this seems to randomly work; it sets the date of some fields to the value of #edit-field, seemingly different fields each time.
also, the form adds more datepicker-enabled fields via ajax. is there any way to ensure that all these new fields, when they load, pick up the value of #edit-field as well?
disclaimer: last night was my first attempt at javascript of any kind. i have a basic idea now. the above was cobbled through countless google examples.