travisbrown
Technical User
- Dec 31, 2001
- 1,016
I'm trying to write one function that will groups together a couple form validation functions. The config below is the only way I can get it to run properly, but I don't understand why I put return on the second function in CheckLineSelectDate(), but not on the first. If I put return on both, it submits the form (this is onsubmit). I'm guessing that if the first function returns true, it allows the submit action before firing the second function? I'm just trying to understand what the priority is.
Cheers.
Cheers.
Code:
function CheckDateOrder(first_date,second_date) {
var fd = document.getElementById(first_date).value;
var sd = document.getElementById(second_date).value;
if ( Date.parse(fd) > Date.parse(sd) ) {
alert("Invalid Date Range.\nStart Date cannot be after End Date!");
return false;
}
}
function CheckSelect(id,msg) {
if ( document.getElementById(id).selectedIndex == 0 ) {
alert(msg);
return false;
}
}
function CheckLineSelectDate() {
CheckSelect('group_id','Please select a group.');
return CheckDateOrder('list_date_start','list_date_end');
}