PDA

View Full Version : cleaning up code


hogtied
02-18-2003, 10:45 AM
Hello,

was just wondering if someone would take the time to see if this part of the script can be cleaned up and easier to read. would be greatly appricated. This part of the code is used when the page loads which doesn't really do anything at all and when the user selects dates from a dropdown list.

this is javascript. just thought it would be easy to read this way...


//called from loadDates(). sets dates either from today's dates or user selection
function setDates(object, inOut) {
var mainForm = document.searchForm;
if(inOut == "checkIn" || inOut == null) { //runs only if onLoad or user modifies CheckIn dates
if(object == mainForm.doa_mm) { //runs only if user modifies CheckIn Month
CIToday.setMonth(object.selectedIndex); //sets the new date to the month selected
if (object.selectedIndex < thisMonth) { //if selected month is lower than this month = next year
CIToday.setYear(thisYear + 1);
}
if (object.selectedIndex >= thisMonth) { //if selected month is = or higher than this month = this year
CIToday.setYear(thisYear);
}
}
if(object == mainForm.doa_dd) { //runs only if user modifies CheckIn Date
CIToday.setDate(object.selectedIndex + 1); //sets the new date to the date selected + 1, computer starts @ 0
if(object.selectedIndex + 1 < thisDate) { //if selected date is lower than this date = next year
CIToday.setYear(thisYear + 1);
}
if(object.selectedIndex + 1 >= thisDate) { //if selectd date is = or higher than this date = this year
CIToday.setYear(thisYear);
}
}

//reset CheckIn dates
CIDay = CIToday.getDay();
CIDate = CIToday.getDate();
CIMonth = CIToday.getMonth();
CIYear = CIToday.getYear();
COToday = new Date(CIYear, CIMonth, CIDate + 1); //sets CheckOut date one day after CheckIn
}
if(object == mainForm.dod_mm) { //runs if user modified CheckOut Month
COToday.setMonth(object.selectedIndex); //sets new date to the Month selected
if(object.selectedIndex < thisMonth) { //if selected month is lower than this month = next year
COToday.setYear(thisYear + 1);
COToday.setDate(1); //sets date back to 1
}
if(object.selectedIndex >= thisMonth) { //if selected month is = or hight than this month = this year
COToday.setYear(thisYear);
}
}

//reset CheckOut dates
CODay = COToday.getDay();
CODate = COToday.getDate();
COMonth = COToday.getMonth();
COYear = COToday.getYear();
return
}

any questions or concerns please feel free to express your thoughts.

thanks,
hogtied