Link to home
Start Free TrialLog in
Avatar of James Rodgers
James RodgersFlag for Canada

asked on

deselect selected item from select box

I have a select box that is activated/deactivated by a check box selection, when the user deacivates the selectbox by unchecking the checkbox i want to clear any selections they have made, that is deselect the selected item so that there is no hightlighted item.
i have tried
obj.selectedIndex=false; // selects first item in list
obj.selectedIndex=0;      // selects first item in list
obj.selectedIndex=-1;    // selects first item in list

obj.options[obj.selectedIndex].selected=false; no results

sorry about the cheap points it's all i have left
ASKER CERTIFIED SOLUTION
Avatar of knightEknight
knightEknight
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
... but I suspect something else is going on.  Can you show us the code you are using on the checkbox to deselect the item?
should be something like this:

<INPUT type="checkbox" name="mycb" onclick="if(!this.checked)this.form.nameOfTheSelect.selectedIndex=-1;" />
Avatar of VincentPuglia
VincentPuglia

this what you looking for?
<html><head>
<script>
function deSelect(selObj)
{
  selObj.options[0].selected = true;
  selObj.options[selObj.selectedIndex].selected = false
}

</script>
</head>
<body>
<form name='a'>
<input type="checkbox" onclick='if (!this.checked) deSelect(this.form.c)'>
<select name="c">
<option selected>Select something</option>
<option>1</option>
<option>1</option>
<option>1</option>
</select>
</form>
</body>
</html>
Avatar of James Rodgers

ASKER

this is my checkbox

<input type="checkbox" value="3" name="optChange3" onclick="if(this.checked)document.frmAddPosition.selEmpList.disabled=false; else {document.frmAddPosition.selEmpList.options[document.frmAddPosition.selEmpList.selectedIndex].selected=false; document.frmAddPosition.selEmpList.disabled=true;}">Edit position holder<br>
so? call the function & make the necessary changes
Vincent,
tried your code with same results

first item in option list is selected and remains selected.

knightEknight

i am going to try your first answer to see if the focus, blur results in the solution i need

Thanks