Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > deselect select list options in IE6

Reply
Thread Tools

deselect select list options in IE6

 
 
armyofda12monkeys
Guest
Posts: n/a
 
      07-06-2007
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/defaul...rogrammingBugs
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[i].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[i].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('te st'));" />
</body>
</html>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can we deselect options in html dynamically (using javascript) ahmad Javascript 2 03-08-2006 01:11 PM
How to deselect item on single select listbox? rpress ASP .Net Web Controls 5 01-09-2006 06:15 PM
How To Deselect From Select Box in IE Notorious Javascript 2 07-15-2005 05:33 PM
How to select all or deselect all checkboxes in datagrid... Al Knowles ASP .Net Datagrid Control 0 12-01-2003 06:22 PM
Deselect any selected items in a select form field with multiple attribute? Keiron Waites Javascript 1 10-21-2003 10:24 AM



Advertisments