Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot unselect selecteditems from select box in IE6 1

Status
Not open for further replies.

Murley

Programmer
Jan 9, 2002
14
US
Hello all I have this function:

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function Unselect(sbox)
{
var i = 0;
for(var i=0; i<sbox.options.length; i++)
{
sbox.options.selected = false;
sbox.options.selectedindex = -1;
}
}
</SCRIPT>

This works in netscape 4.x ie5.x ie 4.x ns6.x but does not work in IE6

I'm calling this function to unselect anythign thats is selected in a <SELECT NAME=blah size=10> box.

Can anyone help me to find a way to do this in IE 6?? as well as all 4.x browsers and higher?
 
Try using document.formname.controlname... Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Yeah i tried that to, actuall i cal it as:

unselect(document.formname.selectname);

and still no luck...

also tried calling is as this.form.....


i'm out of ideas.... Regards,

Chris Murley
Systems Administrator\Programmer
 
Try this :

Code:
<script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>
<!--
  function Unselect(form,sbox) {
    for(var i=0; i<document[form][sbox].options.length;i++) {
      document[form][sbox].options[i].selected = false;
    }
  }
//-->
</script>
<form name=&quot;frm&quot;>
  Select this :<br />
  <select multiple=&quot;multiple&quot; name=&quot;slct&quot; size=&quot;5&quot;>
    <option value=&quot;1&quot;>1</option>
    <option value=&quot;2&quot;>2</option>
    <option value=&quot;3&quot;>3</option>
    <option value=&quot;4&quot;>4</option>
    <option value=&quot;5&quot;>5</option>
  </select>
  <br />Or :<br />
  <input type=&quot;text&quot; onFocus=&quot;Unselect('frm','slct')&quot;>
</form>

I have tested it in : NS3, NS4.7, IE5, IE6 Regards

Big Bad Dave

davidbyng@hotmail.com
 
Cool, that did it. The only difference is that you enclosed the bassed var in [] :) But hey what ever works, I'm into php and perl, and still very rusty with js, but thanks much! Regards,

Chris Murley
Systems Administrator\Programmer
 
Hmm, ok I finally debugged the problem, mine wasnt working because i didnt have:

multiple=&quot;multiple&quot; in my <SELECT> tag.

go to this page:


If you look at the source, the right most top select doesnt work, while the left and bottom ones do, when you change focus to the text box.

My problem is that I dont want these select boxes to be Multiple, I just want to unselect whatever may be select on them. Regards,

Chris Murley
Systems Administrator\Programmer
 
This works with both types of select (dropdown and fixed size), and all browsers :

<script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>
<!--
function unselect(form,field) {
document[form][field].selectedIndex=-1;
}
//-->
</script>
<form name=&quot;frm1&quot;>
<select name=&quot;slct&quot; size=&quot;5&quot;>
<option value=&quot;1&quot;>1</option>
<option value=&quot;2&quot;>2</option>
<option value=&quot;3&quot;>3</option>
<option value=&quot;4&quot;>4</option>
<option value=&quot;5&quot;>5</option>
</select>
<br />
<select name=&quot;slct2&quot;>
<option value=&quot;1&quot;>1</option>
<option value=&quot;2&quot;>2</option>
<option value=&quot;3&quot;>3</option>
<option value=&quot;4&quot;>4</option>
<option value=&quot;5&quot;>5</option>
</select>
<br />
<input type=&quot;text&quot; onfocus=&quot;unselect('frm1','slct');unselect('frm1','slct2')&quot;>
</form> Regards

Big Bad Dave

davidbyng@hotmail.com
 
Once again, ty :) works great, I was going nuts Regards,

Chris Murley
Systems Administrator\Programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top