...

View Full Version : Reset drop down menu



helpmeplease84
01-29-2009, 06:41 PM
I have some code that displays the time in different parts of the world.

These areas are selected from a drop down menu. Once one of them has been selected it stays at that country on the drop down menu.

How can I set it that it returns to the original 'Please Select Country' element?

Many Thanks

CODE:

<html>
<head>
<script language="JavaScript">

function calcTime(city, offset) {
d = new Date();
utc = d.getTime() + (d.getTimezoneOffset() * 60000);
nd = new Date(utc + (3600000*offset));
return " The local date and time in \n \n " + city + " \n \n" + nd.toLocaleString();
}
</script>
</head>

<body>

<!-- Africa Timezones-->

<FORM NAME="myformAfrica" ACTION="" METHOD="GET">
<select id="time" name="bar" onChange="alert(calcTime(document.myformAfrica.bar[document.myformAfrica.bar.selectedIndex] .text, document.myformAfrica.bar.options[document.myformAfrica.bar.options.selectedIndex].value));">

<option selected>Please Select Country</option>
<option value="1">Algiers</option>
<option value="2">Cairo</option>
<option value="2">Cape Town</option>
<option value="0">Casablanca</option>
<option value="2">Durban</option>
<option value="2">Harare</option>
<option value="0">Jamestown</option>
<option value="2">Johannesburg</option>
<option value="1">Lagos</option>
<option value="3">Mamoutzou</option>
<option value="3">Nairobi</option>
<option value="5">Port Louis</option>
<option value="4">Victoria</option>
</select>
</FORM>

</body>
</html>

Philip M
01-29-2009, 07:41 PM
Like so:-


function calcTime(city, offset) {
d = new Date();
utc = d.getTime() + (d.getTimezoneOffset() * 60000);
nd = new Date(utc + (3600000*offset));
document.myformAfrica.bar.options.selectedIndex = 0;
return " The local date and time in \n \n " + city + " \n \n" + nd.toLocaleString();
}

Or if you prefer:-


<select id="time" name="bar" onChange="alert(calcTime(document.myformAfrica.bar[document.myformAfrica.bar.selectedIndex].text, document.myformAfrica.bar.options[document.myformAfrica.bar.options.selectedIndex].value));document.myformAfrica.bar.options.selectedIndex = 0;">



Quizmaster: Which African country gives its name to the complaint known as 'gippy tummy'?
Contestant: Venezuela.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum