I am currently trying to build a booking page for a theatre website, the dates of the shows are set to specific days of the week but run indefinitely throughout the year.
My current brain-tickling task is that of creating a function that will correctly update the show dates to be the nearest relevant numerical date to todays date.
So, from todays date, I need it to show options for Friday 25th January, Saturday 26th January and Wednesday 30th January, then if accessed tomorrow (Friday 25th January 2013) it would change the date of Friday to 1st February (as that is the next friday showing).
I suppose the function would go something like this (in logical terms):
updateShowDates(function(){
var todaysdate = getDate
var todayWeekday = getDay
var showWeekday = document.getElementByName('datepicker').value
var lengthtotarget = count number of days between todayWeekday and target weekday (i.e. Wednesday)
newShowDate = todaysdate + lengthtotarget
document.getElementByName('datepicker').innerHTML=newShowDate;
});
The HTML for the element that this will function on is:
<select id="dateselect" size="3">
<option value="Wednesday" title="Wednesday" name="datepicker">
Wednesday
</option>
<option value="Friday" title="Friday" name="datepicker">
Friday
</option>
<option value="Saturday" title="Saturday" name="datepicker">
Saturday
</option>
</select>
I am a bit of a noob with Javascript, I did find a resource a while ago that would be very helpful for this but of course, sod's law, I didn't bookmark it and can't find it anymore.
Any help to write a working function would be greatly appreciated. This is for university coursework and of course I am trying to score the highest possible mark.