Results 1 to 4 of 4

Thread: IE/Firefox javascript html list issue

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

    Default IE/Firefox javascript html list issue

    The following code snippet works in Firefox but not in IE. However, if I have the alert message at that particular location, it works in IE as well.

    Am I missing something

    /*
    * This method selects all the items in the list if "All" (index position 0)
    * is selected
    */
    function selectAll(){
    var combo = document.getElementById('item');
    alert("If this alert is present it works in IE");
    var val1 = combo.options[combo.selectedIndex].value;
    for( var i = 0; i < combo.options.length; i++ ) {
    if(val1 == 0){
    combo.options[i].selected = true;
    }
    }
    }

    <s:select list="elements" name="item" headerKey="0" headerValue="ALL"
    multiple="true" size="4" id="item" onclick="selectAll);"></s:select>

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    tested in IE and FF

    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" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    /*<![CDATA[*/
    /*
    * This method selects all the items in the list if "All" (index position 0)
    * is selected
    */
    function selectAll(){
    var combo = document.getElementById('item');
    var val1 = combo.options[combo.selectedIndex].value;
    alert("If this alert is present it works in IE");
    for( var i = 0; i < combo.options.length; i++ ) {
    if(val1 == '0'){
    combo.options[i].selected = true;
    }
    }
    }
    
    /*]]>*/
    </script></head>
    
    <body>
    <select list="elements" name="item" headerKey="0" headerValue="ALL"
    multiple="true" size="4" id="item" onclick="selectAll();">
    <option value="0" >11111111</option>
    <option value="1" >11111111</option>
    <option value="2" >11111111</option>
    <option value="3" >11111111</option>
    </select>
    
    </body>
    
    </html>

  3. #3
    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

    If you are going to use that DOCTYPE, use valid markup for it:

    Code:
    <body>
    <div>
    <select name="item" 
    multiple="multiple" size="4" id="item" onclick="selectAll();">
    <option value="0" >11111111</option>
    <option value="1" >11111111</option>
    <option value="2" >11111111</option>
    <option value="3" >11111111</option>
    </select>
    </div>
    
    </body>
    However, an HTML 4.01 strict DOCTYPE is preferred in almost all cases. HTML 4.01 transitional may be used if the markup cannot made to validate strict.
    - John
    ________________________

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

  4. #4
    Join Date
    Dec 2008
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Tried out the code that you send, it didn't work. Maybe because I want it to work in IE 6 and from what I see below the problem is resovled in IE 7.

    I can't believe this... The solution is easier that it seems but the explanation a bit flakey....

    "Cross browser compatibility issues. Changing onclick to onchange has resolved the problem."
    http://www.webdeveloper.com/forum/sh...032#post960032

    Thanks guys for your help.

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
  •