Part of the form I'm creating has two fields, a day field and a date field. The user will input a date in field 1 (Date) and field 2 (Day) will automatically be populated with the day of the week for that date. I've been trying to piece together the code for the things I need to do (auto-populating a field, returning a day of the week, etc) but it doesn't seem to be working out for me. I'm using Javascript (read: no JQuery).
Here are is the relevant portion of my HTML:
<label>
<span>input date</span>
<input type="date" id="date" onChange="getBegDay()">
</label>
<label>
<span>return day</span>
<input readonly type="text" id="day">
</label>
Here is the relevant portion of my Javascript:
function getBegDay() {
var v = document.getElementById("date").value;
var n = v.split('-');
var y = n[0];
var m = n[1];
var d = n[2];
var g = new date(y,m,d);
var weekday = new array(7);
var weekday[0] = "Sunday";
var weekday[1] = "Monday";
var weekday[2] = "Tuesday";
var weekday[3] = "Wednesday";
var weekday[4] = "Thursday";
var weekday[5] = "Friday";
var weekday[6] = "Saturday";
var wd = weekday[g.getDay()];
document.getElementById('day').value = wd;