Shifting Form Field Values onclick

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
millsy007
Forum Commoner
Posts: 78
Joined: Wed Jul 02, 2008 7:00 pm

Shifting Form Field Values onclick

Post by millsy007 »

I have a page from which the user can select a date (in a text box updated via a calendar) and a time (selected from an options list)
I have two links that let the user cycle through the date field.

Code: Select all

<a href="#" onclick="shiftDate(1, 'down');">Previous</a>
<a href="#" onclick="shiftDate(1, 'up');">Next</a>
My javascript then changes the date accordingly

Code: Select all

function shiftDate(days, up_or_down)
{
date = new Date(document.getElementById('date').value);
 
if (up_or_down == 'up') {
date.setDate(date.getDate() + days);
} else {
date.setDate(date.getDate() - days);
}
 
document.getElementById('date').value = (date.getMonth()+1)+"/"+date.getDate()+"/"+date.getFullYear();
GetSchedule();
return false;
}
This works fine but i need to incorporate the time option too. The time dropdown list has:

Code: Select all

<select name="time" id="time" style="width:150px">
      <option>Select Time</option>
      <option value="9:00">Morning</option>
      <option value="12:00">Afternoon</option>
      <option value="16:00">Evening</option>
      <option value="22:00">Late</option>
</select> 
 
What I would like to happen is that when the user clicks the 'next' it firstly updates the time, moving on one option value in the time field, and then only if the option value is <option value="22:00">Late</option> shifting/moving on 1 day.

Is this possible? I cant seem to get this functionality working
Post Reply