Return to Snippet

Revision: 39539
at January 18, 2011 05:48 by shinokada


Initial Code
function convert_date_to_human_readable(){
var $this=$(this);
var id='date-input-'+Math.random().toString()
.replace(/\./,'');
var dparts=$this.val().split(/-/);
$this
.datepicker({
dateFormat:'yy-mm-dd',
modal:true,
altField:'#'+id,
altFormat:'DD, d MM, yy',
onSelect:function(dateText,inst){
this.value=dateText;
}
});
var $wrapper=$this.wrap(
'<div style="position:relative" />');
// Usage this in html,php
//<input name="associated_date" class="date-human" value="',$page['associated_date'],'" />
//...

var $input=$('<input id="'+id+'" class="date-human-readable"
value="'+date_m2h($this.val())+'" />');
$input.insertAfter($this);
$this.css({
'position':'absolute',
'opacity':0
});
$this
.datepicker(
'setDate', new Date(dparts[0],dparts[1]-1,dparts[2])
);
}
$(function(){
$('input.date-human').each(convert_date_to_human_readable);
});

Initial URL

                                

Initial Description
From webworks, book "CMS Design Using Php and jQuery", page 93

Initial Title
convert_date_to_human_readable

Initial Tags
date

Initial Language
JavaScript