Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-29-2009, 05:41 PM   PM User | #1
helpmeplease84
New to the CF scene

 
Join Date: Jan 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
helpmeplease84 is an unknown quantity at this point
Reset drop down menu

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>
helpmeplease84 is offline   Reply With Quote
Old 01-29-2009, 06:41 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Like so:-

Code:
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:-

Code:
<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.

Last edited by Philip M; 01-29-2009 at 06:47 PM..
Philip M is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:55 PM.


Advertisement
Log in to turn off these ads.