javascript code to display the day

Status
Not open for further replies.

thecreativeboy

Journeyman
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.
 

Kalyan

Journeyman
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
 
Status
Not open for further replies.
Top Bottom