Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •