javascript code to display the day

Discussion in 'Programming' started by thecreativeboy, Jun 30, 2009.

Thread Status:
Not open for further replies.
  1. thecreativeboy

    thecreativeboy New Member

    Joined:
    Jun 25, 2007
    Messages:
    133
    Likes Received:
    0
    Trophy Points:
    0
    i have create one page.and the page is look like

    date : (javascript calendar)

    day:

    so the date can be selected by javascript calendar.what is my question is when i select the date then automatically the day coloum can be filled like(monday,tuesday...........).can anyone please provide me the solution.
     
  2. Kalyan

    Kalyan New Member

    Joined:
    Nov 4, 2005
    Messages:
    243
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Earth
    Here it is..
    function showDay()
    {
    var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

    var dt = new Date(document.getElementById("date").value);
    document.getElementById("day").value = dayarray[dt.getDay()];
    }

    you need to call this method when the event occurs for the calendar to show the date in the date field or you can include this into the script that is in the calendar.. which ever is feasible. The "date" field is supposed to be the textbox with date ( I did it for "MM/dd/yyyy" format) and the "day" field is the textbox where you want to display the date.

    Logic: initialize the date as a Date object. The Date.getDay() gets you the day starting with 0 for Sunday and so on.

    Hope this helps
     
Thread Status:
Not open for further replies.

Share This Page