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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2006
    Posts
    225
    Thanks
    6
    Thanked 3 Times in 3 Posts

    IE7 error: "Object does not support this property or method"

    I've been working on a Javascript time converter for use on my website. It's working perfectly on Firefox and Opera, but throws errors in Internet Explorer 7 (haven't tested on IE6). I can't see any problems with the code. Is there some issue with it that I haven't noticed?

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <
    html xmlns="http://www.w3.org/1999/xhtml">
      <
    head>
        <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <
    script type="text/javascript">

    function 
    convert() {
        
    toTime document.getElementById("timezoneTo");
        
    fromTime document.getElementById("timezoneFrom");
        
    hours Number(document.getElementById("hours").value);
        
    minutes Number(document.getElementById("minutes").value);
        
    pm document.getElementById("ampm").selectedIndex == 1;

      if (
    pm)
        
    hours = (hours == 12) ? 12 hours+12;
      else
        
    hours = (hours == 12) ? hours;

        
    num toTime.options[toTime.selectedIndex].value 60 fromTime.options[fromTime.selectedIndex].value 60;
        
    num += hours 60;
        
    num += minutes;

        if (
    isNaN(num)) { num 0; }
        
    minutes num 60;
        
    num -= minutes;
        
    hours num 60;

        if (
    hours 0) { hours+=24; }
        while (
    minutes 0) { minutes += 30; }
        while (
    hours >= 24) { hours-=24; }
        
    ampm hours >= 12 "PM" "AM";
        if (
    hours 12)
          
    hours -= 12;
        if (
    hours == 0) { hours 12; }
        
    minutes formatTime(minutes);
        
    document.getElementById("converted").innerHTML =   hours+":"+minutes+" "+ampm;
    }

    function 
    formatTime(i) {
      if (
    i<10)
        {
    "0" i}
      return 
    i
    }
        
    </script>
      </head>
      <body onload="convert();">
        <div class="box" id="convert">
          <span class="header">Time Converter</span>
          <div style="margin: 0pt auto;">
          <table>
            <tr>
              <td>Time to convert: </td>
              <td>
                <input size="2" maxlength="2" title="Time (hours)" name="hours" id="hours" value="" onkeyup="convert()" type="text">:<input size="2" maxlength="2" name="minutes" id="minutes" title="Time (minutes)" value="" onkeyup="convert()" type="text">
                <select name="ampm" id="ampm" onchange="convert()">
                  <option value="0" selected="selected">AM</option>
                  <option value="1">PM</option>
                </select>
              </td>
            </tr>
            <tr>
              <td>Converted time:</td>
              <td><span id="converted">12:00 PM</span></td>
            </tr>
          </table>
          <table>
            <tr>
              <td>From time zone:</td>
              <td>
                <select name="timezoneFrom" id="timezoneFrom" onchange="convert();">
                  <option value="-12">(GMT - 12:00 hours) Enitwetok, Kwajalien</option>
                  <option value="-11">(GMT - 11:00 hours) Midway Island, Samoa</option>
                  <option value="-10">(GMT - 10:00 hours) Hawaii</option>
                  <option value="-9">(GMT - 9:00 hours) Alaska</option>
                  <option value="-8">(GMT - 8:00 hours) Pacific Time (US &amp; Canada)</option>
                  <option value="-7">(GMT - 7:00 hours) Mountain Time (US &amp; Canada)</option>
                  <option value="-6">(GMT - 6:00 hours) Central Time (US &amp; Canada), Mexico City</option>
                  <option value="-5">(GMT - 5:00 hours) Eastern Time (US &amp; Canada), Bogota, Lima</option>
                  <option value="-4">(GMT - 4:00 hours) Atlantic Time (Canada), Caracas, La Paz</option>
                  <option value="-3.5">(GMT - 3:30 hours) Newfoundland</option>
                  <option value="-3">(GMT - 3:00 hours) Brazil, Buenos Aires, Falkland Is.</option>
                  <option value="-2">(GMT - 2:00 hours) Mid-Atlantic, Ascention Is., St Helena</option>
                  <option value="-1">(GMT - 1:00 hours) Azores, Cape Verde Islands</option>
                  <option value="0">(GMT) Casablanca, Dublin, London, Lisbon, Monrovia</option>
                  <option value="1">(GMT + 1:00 hours) Brussels, Copenhagen, Madrid, Paris</option>
                  <option value="2">(GMT + 2:00 hours) Kaliningrad, South Africa</option>
                  <option value="3">(GMT + 3:00 hours) Baghdad, Riyadh, Moscow, Nairobi</option>
                  <option value="3.5">(GMT + 3:30 hours) Tehran</option>
                  <option value="4">(GMT + 4:00 hours) Abu Dhabi, Baku, Muscat, Tbilisi</option>
                  <option value="4.5">(GMT + 4:30 hours) Kabul</option>
                  <option value="5">(GMT + 5:00 hours) Ekaterinburg, Karachi, Tashkent</option>
                  <option value="5.5">(GMT + 5:30 hours) Bombay, Calcutta, Madras, New Delhi</option>
                  <option value="6">(GMT + 6:00 hours) Almaty, Colomba, Dhakra</option>
                  <option value="7">(GMT + 7:00 hours) Bangkok, Hanoi, Jakarta</option>
                  <option value="8">(GMT + 8:00 hours) Hong Kong, Perth, Singapore, Taipei</option>
                  <option value="9">(GMT + 9:00 hours) Osaka, Sapporo, Seoul, Tokyo, Yakutsk</option>
                  <option value="9.5">(GMT + 9:30 hours) Adelaide, Darwin</option>
                  <option value="10">(GMT + 10:00 hours) Melbourne, Papua New Guinea, Sydney</option>
                  <option value="11">(GMT + 11:00 hours) Magadan, New Caledonia, Solomon Is.</option>
                  <option value="12">(GMT + 12:00 hours) Auckland, Fiji, Marshall Island</option>
                </select>
              </td>
            </tr>
            <tr>
              <td>To time zone:</td>
              <td>
                <select name="timezoneTo" id="timezoneTo" onchange="convert();">
                  <option value="-12">(GMT - 12:00 hours) Enitwetok, Kwajalien</option>
                  <option value="-11">(GMT - 11:00 hours) Midway Island, Samoa</option>
                  <option value="-10">(GMT - 10:00 hours) Hawaii</option>
                  <option value="-9">(GMT - 9:00 hours) Alaska</option>
                  <option value="-8">(GMT - 8:00 hours) Pacific Time (US &amp; Canada)</option>
                  <option value="-7">(GMT - 7:00 hours) Mountain Time (US &amp; Canada)</option>
                  <option value="-6">(GMT - 6:00 hours) Central Time (US &amp; Canada), Mexico City</option>
                  <option value="-5">(GMT - 5:00 hours) Eastern Time (US &amp; Canada), Bogota, Lima</option>
                  <option value="-4">(GMT - 4:00 hours) Atlantic Time (Canada), Caracas, La Paz</option>
                  <option value="-3.5">(GMT - 3:30 hours) Newfoundland</option>
                  <option value="-3">(GMT - 3:00 hours) Brazil, Buenos Aires, Falkland Is.</option>
                  <option value="-2">(GMT - 2:00 hours) Mid-Atlantic, Ascention Is., St Helena</option>
                  <option value="-1">(GMT - 1:00 hours) Azores, Cape Verde Islands</option>
                  <option value="0" selected="selected">(GMT) Casablanca, Dublin, London, Lisbon, Monrovia</option>
                  <option value="1">(GMT + 1:00 hours) Brussels, Copenhagen, Madrid, Paris</option>
                  <option value="2">(GMT + 2:00 hours) Kaliningrad, South Africa</option>
                  <option value="3">(GMT + 3:00 hours) Baghdad, Riyadh, Moscow, Nairobi</option>
                  <option value="3.5">(GMT + 3:30 hours) Tehran</option>
                  <option value="4">(GMT + 4:00 hours) Abu Dhabi, Baku, Muscat, Tbilisi</option>
                  <option value="4.5">(GMT + 4:30 hours) Kabul</option>
                  <option value="5">(GMT + 5:00 hours) Ekaterinburg, Karachi, Tashkent</option>
                  <option value="5.5">(GMT + 5:30 hours) Bombay, Calcutta, Madras, New Delhi</option>
                  <option value="6">(GMT + 6:00 hours) Almaty, Colomba, Dhakra</option>
                  <option value="7">(GMT + 7:00 hours) Bangkok, Hanoi, Jakarta</option>
                  <option value="8">(GMT + 8:00 hours) Hong Kong, Perth, Singapore, Taipei</option>
                  <option value="9">(GMT + 9:00 hours) Osaka, Sapporo, Seoul, Tokyo, Yakutsk</option>
                  <option value="9.5">(GMT + 9:30 hours) Adelaide, Darwin</option>
                  <option value="10">(GMT + 10:00 hours) Melbourne, Papua New Guinea, Sydney</option>
                  <option value="11">(GMT + 11:00 hours) Magadan, New Caledonia, Solomon Is.</option>
                  <option value="12">(GMT + 12:00 hours) Auckland, Fiji, Marshall Island</option>
                </select>
              </td>
            </tr>
          </table>
          </div>
        </div>
      </body>
    </html> 
    I'd also appreciate any comments if I am converting the time inefficiently, or there is a better way to do something.

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    You have ID names the same as variables I do not think IE allows this

    Here's few snippets from your code

    hours = Number(document.getElementById("hours").value);

    minutes = Number(document.getElementById("minutes").value);

    pm = document.getElementById("ampm").selectedIndex == 1;


    ampm = hours >= 12 ? "PM" : "AM";
    Last edited by Mr J; 08-25-2007 at 12:21 PM.
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • Users who have thanked Mr J for this post:

    name _F1 (08-25-2007)

  • #3
    Regular Coder
    Join Date
    Jun 2006
    Posts
    225
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Thank you! I figured it must be a problem with the variable names but I couldn't figure out exactly what the problem was. I'll know to avoid this in the future.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    I think it will make IE happy if you make the hours variable local by using the var keyword. Remember that if you don't declare a variable with a var keyword, it is considered global and all id'ed and named tags in IE can be accessed directly because IE also treats them as global variables. I think what's happening there is IE gets confused because IE sees both your variable hours and the id hours in global scope. It doesn't know which variable you are referring to.

    Code:
    function convert() {
        toTime = document.getElementById("timezoneTo");
        fromTime = document.getElementById("timezoneFrom");
        var hours = Number(document.getElementById("hours").value);
       ...
    }
    But it is indeed a good programming practice to avoid identical names/ids and variables.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Avex DVD to Mobile Converter converts DVD movies to Mobile Phone 3GP format and let you watch mobile movies on the road.

    http://www.mobile-video-converter.com/


  •  

    Posting Permissions

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