PDA

View Full Version : Change weekday by date



Manny
07-17-2006, 12:27 PM
Hi guys,

As I'm hopeless with Javascript, I've been searching for a way to change the weekday in a text box by date selection in a drop down.

I am trying to design a timecard application where users can insert upto 10 records in the database at a time. Each row starts with date which (drop down shows the last 28 dates) - when the user selects any date from this list, I need the value in the input box next to it to change to the weekday corresponding with the date.

However, I need to keep the value of the date in the drop down too, ie, I need the date and the day as parameters for the next page, so, the following won't work:

<html>
<head></head>
<body>

<form id="myform" name="myform" method="post" action="gotonextpage.asp">

<select id="mydates" name="mydates"
onchange="document.getElementById('myday').value=this[this.selectedIndex].value">
<option value="Monday">17/07/2006</option>
<option value="Sunday">16/07/2006</option>
<option value="Saturday">15/07/2006</option>
</select><br />


<input id="myday" name="myday" type="text" value="" /><br />

<input type="submit" value="Submit" />
<input type="reset" value="Clear" />
</form>

</body>
</html>


Any help will be greatly appreciated.

Regards,

Manny

Twey
07-17-2006, 12:43 PM
<script type="text/javascript">
var monthDB = {
'17/07/2006' : 'Monday',
'16/07/2006' : 'Sunday',
'15/07/2006' : 'Saturday'
};
</script>
<select onchange="this.form.elements['myday'].value = monthDB[this.value];">
<option value="17/07/2006">17/07/2006</option>
<option value="16/07/2006">16/07/2006</option>
<option value="15/07/2006">15/07/2006</option>
</select>

Manny
07-17-2006, 01:17 PM
Hi Twey,

You are a superstar!! I've been trying to get this working for five days now and always managed to do one bit but not the other. You've just saved me a lot of time.

Thanks again,

Manny :)