deselect select list options in IE6

Discussion in 'Javascript' started by armyofda12monkeys, Jul 6, 2007.

  1. Hello all,

    When I click on a select list to choose an option, then i click on a
    button which runs some code which does stuff,
    then tries to unset the option in the list. In IE it doesnt work, when
    it seems like it should.

    Also anyone know why this problem occurs, i went through
    http://channel9.msdn.com/wiki/default.aspx/Channel9.InternetExplorerProgrammingBugs
    but didnt find any bugs with .selected attribute listed.

    My code is attached at end: FF unsets the select with all 3 functions
    i try. IE goofs up on all but the last but i wasnt sure if the last is
    the best approach.

    thanks,
    Ari

    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=utf-8" />
    <title>TEST</title>
    <script type="text/javascript">

    function deselectList1(listID)
    {
    var optionsList = listID.getElementsByTagName('option');

    for (i = optionsList.length - 1; i>=0; i--) //for(var i=0; i <
    options.length; i++)
    {
    optionsList.selected = false;
    }

    }
    function deselectList2(listID)
    {
    var optionsList = listID.getElementsByTagName('option');

    optionsList[listID.selectedIndex].selected = false;
    }
    function deselectList3(listID)
    {
    var optionsList = listID.getElementsByTagName('option');

    try
    {
    listID.selectedIndex = -666;
    }catch (e)
    {
    //alert('length'+ optionsList.length)
    for (i = optionsList.length - 1; i>=0; i--) //for(var i=0; i <
    options.length; i++)
    {
    optionsList.selected = false;
    }
    }

    }

    </script>
    </head>

    <body>
    <select size="5" name="test" id="test">
    <option>AAAA</option>
    <option>BBBB</option>
    <option>CCCC</option>
    </select>
    <input name="btn" type="button" value="unselect list"
    onclick="deselectList1(document.getElementById('test'));" />
    </body>
    </html>
     
    armyofda12monkeys, Jul 6, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Al Knowles

    How to select all or deselect all checkboxes in datagrid...

    Al Knowles, Dec 1, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    246
    Al Knowles
    Dec 1, 2003
  2. rpress

    How to deselect item on single select listbox?

    rpress, Jan 3, 2006, in forum: ASP .Net Web Controls
    Replies:
    5
    Views:
    1,548
    rpress
    Jan 9, 2006
  3. Keiron Waites
    Replies:
    1
    Views:
    127
    Keiron Waites
    Oct 21, 2003
  4. Notorious

    How To Deselect From Select Box in IE

    Notorious, Jul 15, 2005, in forum: Javascript
    Replies:
    2
    Views:
    111
    Notorious
    Jul 15, 2005
  5. ahmad
    Replies:
    2
    Views:
    87
    Michael Winter
    Mar 8, 2006
Loading...

Share This Page