The only place you have defined
addDueDate is in this code:
Code:
function addList () {
var addDueDate=document.list.datedue.value;
var addToList=document.list.todo.value;
document.getElementById("todolist").innerHTML= "<table><tr><td> Due Date </td><td>Task</td></tr><tr><td>" + addDueDate + "</td><td> " + addToList +"</td></tr></table>";
}
But that variable is FUNCTION SCOPE, meaning that as soon as the addList() function is finished running, that variable is gone into the ether. Zap. Non-existent.
You could move the variable to global scope, but I think that's a bad idea.
A little extra code isn't going to hurt, especially if it keeps intent clear:
Code:
function validDate() {
var re= /^\d{2}[.\/-]\d{2[.\/-]\d{4}$/;
if (re.test(document.list.datedue.value)== false) {
alert("please enter a valid date");
}
}
NOW...there's another problem: You don't DO this validation until *AFTER* the item has ALREADY been "published" in the <table>. (And, by the by, it's bad practice to use innerHTML to generate an entier <table>, most experts would say.)
So wouldn't it make more sense to simply incorporate the test into the the addList( ) function and then *NOT* publish to the <table> if the date is invalid?
*NOW* you could simply do:
Code:
function addList () {
var addDueDate=document.list.datedue.value;
var re= /^\d{2}[.\/-]\d{2[.\/-]\d{4}$/;
if ( ! re.test(addDueDate) ) {
alert("please enter a valid date");
return;
}
var addToList=document.list.todo.value;
document.getElementById("todolist").innerHTML= "<table><tr><td> Due Date </td><td>Task</td></tr><tr><td>" + addDueDate + "</td><td> " + addToList +"</td></tr></table>";
}
And get rid of your validDate() function and the call to it.