Java Reference
In-Depth Information
The function updateTimeZone() updates two of these, setting the variable timeDiff to the value of
the list's selected option (that is, the time difference between the selected city and UTC time) and the
variable selectedCity to the text shown for the selected option (that is, the selected city).
function updateTimeZone()
{
var lstCity = document.form1.lstCity;
timeDiff = lstCity.options[lstCity.selectedIndex].value;
selectedCity = lstCity.options[lstCity.selectedIndex].text;
In the fi nal part of the function updateTimeZone(), the function updateTime() is called, as shown in
the following:
updateTime();
}
Before you go on to look at this function, you return to the fi nal part of the form on the page. This is a
check box, which the user clicks if the city she has chosen from the select list is in the summertime of a
country that uses daylight savings hours.
<input type=”checkbox” name=”chkDaylightSaving”
onclick=”return chkDaylightSaving_onclick()“>
As you can see, this check box's click event is connected to another function,
chkDaylightSaving_onclick().
function chkDaylightSaving_onclick()
{
if (document.form1.chkDaylightSaving.checked)
{
daylightSavingAdjust = 60;
}
else
{
daylightSavingAdjust = 0;
}
Inside the if statement, the code accesses the check box's checked property, which returns true if it is
checked and false otherwise. If it has been checked, you set the global variable daylightSavingAdjust
to 60 for summertime daylight savings; otherwise it's set to 0.
updateTime();
}
At the end of this function (as at the end of the function updateTimeZone() you saw earlier), the
updateTime() function is called. You'll look at that next.
In the function updateTime(), you write the current local time and the equivalent time in the selected
city to the results DIV with ID ConversionResultsDIV, which you defi ned in the frameset page.
You start at the top of the function by creating a new Date object, which is stored in the variable nowTime.
The Date object will be initialized to the current local time.
function updateTime()
{
var nowTime = new Date();
Search WWH ::




Custom Search