Enam Ajmal Enam Ajmal - 7 months ago 13
Javascript Question

i wan to get the name of day and month

i want to get the name of day and month the following script working properly but now i want to display the name of the day of selected date and name of the month to.

$(document).ready(function() {
$("#departing").datepicker({
dateFormat: "yy-mm-dd",
onSelect: function() {
var m_names = ["January", "February", "March",
"April", "May", "June", "July", "August", "September",
"October", "November", "December"];

var selected = $(this).val(),
selectedToArray = selected.split('-'),
year = selectedToArray[0],
month = selectedToArray[1],
day = selectedToArray[2];

$('#date').text(year);
$('#month').text(month);
$('#day').text(day);
}
});
});

Answer

Just try this:

<script type="text/javascript"> 
$( document ).ready(function() {
$("#departing").datepicker(  { 
dateFormat: "yy-mm-dd", 
onSelect: function() {

var m_names = ["January", "February", "March", 
                "April", "May", "June", "July", "August", "September", 
                "October", "November", "December"];


  var 
    selected = $(this).val(),
    selectedToArray = selected.split('-'),
    year = selectedToArray[0],
    month = selectedToArray[1],
    day = selectedToArray[2];

    month = month.replace(/^0+/, ''); // add this line to remove leading zero , so we can ferch proper value from array
    $('#date').text(year);
    $('#month').text(m_names[month]); // access with m_names[month]
    $('#day').text(day);
 } 
 });
});
</script>