I’m just a beginner in Javascript.
I have created an asp page (Week.asp), where there is a form (frmDayAdd). On this form the user can enter a date by clicking on a button and a new window pops up with a calendar. When they click on required date, the calendar window is closed and the date passed to the form field (txtDate) in format dd/mm/yyyy. When the user then clicks the drop down select box (cboTarget) it triggers the javascript function (getDays). This then finds the corresponding day (e.g. Monday) to the date selected (txtDate) and writes it to the table cell (id=’spnDay’).
This all appears to work ok (i.e. a day is shown when above process is carried out) however, the days passed are not the correct days for the date. I think the code is getting confused somewhere with GMT & UTC time formats.
I want it all to work with GMT.
Ive tried various things but with no success, as I said before Ive only just started working with JavaScript.
I would be very grateful if anyone could tell me how to adapt my code
I hope this all makes sense.
My Code is below.
[code=html]…………………………………………………………………………………………………
function getDays(aText)
{
myDays=[“Sunday”,”Monday”,”Tuesday”,”Wednesday”,”Thursday”,”Friday”,”Saturday”,”Sunday”];
myDate=new Date(eval(‘”‘+aText.value+'”‘));
spnDay.innerHTML=myDays[myDate.getDay()]
}
<table align=”center” width=”60%” border=”0″ cellspacing=”1″ cellpadding=”5″>
<form action=”Week.asp?WeekID=<%=strWeekID%>&Day=Add&Mode=Edit” name=”frmDayAdd” Method=”Post”>
<tr>
<td> </td>
<td><input type=”text” name=”txtDate_vis” Value=”<%=strDate%>” size=”15″ style=”font-family: Verdana; font-size: 10pt”>
<input type=”button” value=”…” onClick=”OpenDateWin(‘Y’,’txtDate’,’frmDayAdd’)”>
<input type=”hidden” name=”txtDate” Value=”<%=strDate%>”></td>
<td class=”content” id=’spnDay’></td>
<td><select name=”cboTarget” onFocus=”getDays(frmDayAdd.txtDate_vis)” style=”font-family: Verdana; font-size: 10pt”>
<option value=””>Select</option></td>
</tr>
</table>
…………………………………………………………………………………………………