Results 1 to 2 of 2

Thread: Why This Script is not working With IE7.

  1. #1
    Join Date
    Jul 2008
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Why This Script is not working With IE7.

    Why This Script is not working With IE7. it is running in Firefox.

    Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script type="text/javascript" language="javascript">
    function sel(val)
    {
    	var sMonth = document.getElementById('idMonthOption').value;
    	//alert(idMonthOption.value);
    //	alert(sMonth);
    	alert(val);
    }
    </script>
    </head>
    
    <body>
    <form name="XX">
       <select name="selectMonth" >
        <option >Monat wählen</option>
        	
    	    <option value="2006-26"  id="idMonthOption" onclick="sel('Hello')" > 2006-26 </option>
            <option value="2006-27" id="idMonthOption" onclick="sel('Hello1')" > 2006-27 </option>
      </select>
      </form>
    </body>
    </html>
    Last edited by jscheuer1; 07-04-2008 at 08:01 AM. Reason: format code

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    It shouldn't work in FF either, but FF is error correcting the code for you. In javascript only one unique id is allowed per page. The script has no way to know which element that this line:

    Code:
    var sMonth = document.getElementById('idMonthOption').value;
    refers to.

    So it is just a matter of FF skipping the error by simply picking the first one it finds, and IE barfing on the error. Either way, it is still an error and would need to be corrected.

    If you remove the comments, you will see that FF always picks:

    Code:
    <option value="2006-26" id="idMonthOption" onclick="sel('Hello')" > 2006-26 </option>
    when determining what:

    Code:
    var sMonth = document.getElementById('idMonthOption').value;
    and:

    Code:
    idMonthOption.value
    are, regardless of which one is clicked.
    Last edited by jscheuer1; 07-05-2008 at 01:38 PM. Reason: English Usage
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    bhagwat (07-05-2008)

Bookmarks

Posting Permissions

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