oDay is undefined

Hello guys,

I have this javascript undefined:

function:

function printInternationalDate(date, oDay, oMonth, oYear)
{
	oDay.value = date.getDate();
	oMonth.value = fixMonth(date.getMonth());
	oYear.value = date.getFullYear();
}

HTML:


						<select name="fromDateDay" id="fromDateDay">
							<option value="">- Day -</option>
<%		for x = 1 to 31 %>
							<option value="<%= x %>" <% if fromDateDay = x then response.write("selected") %> ><%= x %></option>
<%		next %>
						</select>

calling function:

<a class="SmallLinks" href="javascript:InternationalDateRange('Week to Date', document.forms[0].fromDateDay, document.forms[0].fromDateMonth, document.forms[0].fromDateYear, document.forms[0].toDateDay, document.forms[0].toDateMonth, document.forms[0].toDateYear)">Week to Date</a>

generated HTML:

			
						<select name="fromDateDay" id="fromDateDay">
							<option value="">- Day -</option>

							<option value="1" selected >1</option>

							<option value="2"  >2</option>

							<option value="3"  >3</option>

							<option value="4"  >4</option>

							<option value="5"  >5</option>

							<option value="6"  >6</option>

							<option value="7"  >7</option>

							<option value="8"  >8</option>

							<option value="9"  >9</option>

							<option value="10"  >10</option>

							<option value="11"  >11</option>

							<option value="12"  >12</option>

							<option value="13"  >13</option>

							<option value="14"  >14</option>

							<option value="15"  >15</option>

							<option value="16"  >16</option>

							<option value="17"  >17</option>

							<option value="18"  >18</option>

							<option value="19"  >19</option>

							<option value="20"  >20</option>

							<option value="21"  >21</option>

							<option value="22"  >22</option>

							<option value="23"  >23</option>

							<option value="24"  >24</option>

							<option value="25"  >25</option>

							<option value="26"  >26</option>

							<option value="27"  >27</option>

							<option value="28"  >28</option>

							<option value="29"  >29</option>

							<option value="30"  >30</option>

							<option value="31"  >31</option>

						</select>

Error is:

oDay is undefined… I am not sure why it is…

that error occurs when I click the link “Week to Date”

The link calls the InternationalDateRange() function which you haven’t shown. Is the printInternationalDate() function called from there?

It will be easiest to come to a quick solution if we had a web page that we could experience this on.

Hello,

The printInternationalDate() function is shown on the above thread. Here is the generated HTML, please see attachment.

Thanks in advance.

The problem occurs with oDay that is passed to the printInternationalDate() function, so what needs to be found is the code that calls that function.

Okay, it’s still awaiting approval at this stage.

<a class="SmallLinks" href="javascript:InternationalDateRange('Week to Date', document.forms[0].fromDateDay, document.forms[0].fromDateMonth, document.forms[0].fromDateYear, document.forms[0].toDateDay, document.forms[0].toDateMonth, document.forms[0].toDateYear)">Week to Date</a>

That’s it…

I don’t see printInternationalDate in that lot. What I do see there is InternationalDateRange

Here it is:

That HTML is is calling InternationalDateRange function, and that function is calling printInternationalDate function.

function InternationalDateRange(sRange, oFromDate_day, oFromDate_month, oFromDate_year, oToDate_day, oToDate_month, oToDate_year)
{
	//the current date
	date = new Date();
	//1000 seconds in a millisecond, 60 seconds in a minute, etc...
	var day = 1000 * 60 * 60 * 24;
	
	//loop through acceptable date ranges
	switch (sRange)
	{
		case "Week to Date":
			/* To: Today */ printInternationalDate(date, oToDate_day, oToDate_month, oToDate_year);
			
			//subrtact day of the week number of days from today
			date.setTime( date.getTime() - fixDay(date.getDay()) * day );
			/* From: First Day of the Week */ printInternationalDate(date, oFromDate_day, oFromDate_month, oFromDate_year);
			break;

	}
}

Okay, so oToDate_day is giving the undefined value, which comes from the 5th parameter that is passed to InternationalDateRange

Now we know where the undefined value is coming from, it’s coming from document.forms[0].toDateDay

Where is toDateDay?

						<select name="toDateDay" id="toDateDay">
							<option value="">- Day -</option>
<%		for x = 1 to 31 %>
							<option value="<%= x %>" <% if toDateDay = x then response.write("selected") %> ><%= x %></option>
<%		next %>
						</select>

That’s great, so we’ve come to the end of basic troubleshooting.

Next up is to experience the script and the generated html together within the web browser, so that finer details can be discovered.

Do you happen to have something as a web page somewhere so that the problem can be experienced, so that a solution can be found for you?

No, I have only a copy in my localhost.

Actually this works before in IE and Firefox, but when I changed this DTD from transitional to strict, it does not work now in IE and Firefox.

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>

to

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>

So, I am thinking the issue here is the some elements don’t work in strict. Maybe the elements are not compatible with strict DTD.

This extra information means that it’ strongly likely to be a structural problem with the HTML code itself.

In cases like this, fixing HTML problems within the code has a high chance of success towards fixing the problem.

Run the HTML code through http://validator.w3.org/ and see how the script performs once the HTML code passes validation.