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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WORKS IF LIST IS SELECT MULTIPLE BUT NOT SINGLE 1

Status
Not open for further replies.

LikeThisName

Vendor
May 16, 2002
288
US
THIS CODE WORKS IF LIST IS SELECT MULTIPLE

Code:
    for (i=0;i<List.length;i++)
    {
        List.options[i].selected = false;
    }

I need it to work on single select

in a single select once you select you can't seem to unselect so is changing it from a single to a multiple to use the code above then change back to single

AN OPTION?

TIA,

LikeThisName <- ? Sorry It's Taken =)
 
This one is a simple one-liner:
Code:
List.selectedIndex = -1
and here's an example you can copy/paste to test yourself:
Code:
<body>
<form name=blahForm>
<select name=blahSelect>
<option>1
<option>2
<option>3
</select>
<input type=button value='Unselect' onclick='document.blahForm.blahSelect.selectedIndex = -1'>
</form>
</body>

-kaht

banghead.gif
 
one-liner worked great, just what i needed. i don't even need the for loop. thanks for the fast response would have thanked you earlier but site was down.




LikeThisName <- ? Sorry It's Taken =)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top