I am a total jQuery noob, and this is my first serious attempt to do something with it. I have a form with 3 select boxes for day, month, and year. When the day box is changed, I want to show the day of the week in a division. The code I’ve written works the first time I execute it. But if I change the day a second time, I get an error.
Here’s my document.ready function:
$(document).ready(function() {
// arrival day box is changed
$('select#a_day').change(function () {
alert('arrival day was changed to ' + $('.selday').val());
var theyear = $('select#a_year').val();
var themonth = $('select#a_month').val();
var theday = $('select#a_day').val();
alert(theday + '/' + themonth + '/' + theyear);
dayofweek = weekday(theday,themonth,theyear);
$('#dowtext').html(dayofweek);
alert(dayofweek);
});
});
(the alerts are just there for debugging)
and a couple of helper functions:
function calcweekday(adate) {
var dow = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
aweekday = adate.getDay();
return dow[aweekday];
}
// onblur function:
function weekday(day,month,year) {
adate = new Date(year,month-1,day);
if (adate) {
weekday = calcweekday(adate);
return weekday;
}
}
The error I get is on this line:
dayofweek = weekday(theday,themonth,theyear);
and the error is a type mismatch on the line in red above. So it seems like those three variables aren’t valid any more after the first time. Help! Can anyone explain this to me?