Cara menampilkan tanggal, bulan dan tahun saat datetimepicker muncul

Assalamu'alaikum wr wb.
Kali ini saya akan share bagaimana caranya saat memilih tanggal di jquery ui muncul tanggal, bulan dan tahun pada pilihannya.
Berikut ini syntaxnya.

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>jQuery UI Datepicker - Default functionality</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <script>
        $(function() {
            $( "#datepicker" ).datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
yearRange: '1950:2013'
});
        });

        window.onload=function(){
            $('#datepicker').on('change', function() {
                var dob = new Date(this.value);
                var today = new Date();
                var age = Math.floor((today-dob) / (365.25 * 24 * 60 * 60 * 1000));
var bln = Math.floor((today-dob) / (365.25 * 24 * 60 * 60 * 1000));
var hr = Math.floor((today-dob) / (365.25 * 24 * 60 * 60 * 1000));
var thr = Math.floor((today-dob) / (365.25 * 24 * 60 * 60 * 1000));
                $('#umur').val(age);
$('#bulan').val(bln);
$('#hari').val(hr);
$('#thari').val(thr);
            });
        }

    </script>
</head>
<body>
    <p>Tanggal Lahir: <input type="text" id="datepicker"></p>
   
</body>
</html>

Semoga bermanfaat.
http://pangeran-it.blogspot.com/
Cara menampilkan tanggal, bulan dan tahun saat datetimepicker muncul Cara menampilkan tanggal, bulan dan tahun saat datetimepicker muncul Reviewed by Syawaluddin Amin, S.Kom on November 28, 2014 Rating: 5

2 komentar:

Diberdayakan oleh Blogger.