James Rodgers
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.selectedIn dex].selec ted=false; no results
sorry about the cheap points it's all i have left
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.selectedIn
sorry about the cheap points it's all i have left
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
... 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. nameOfTheS elect.sele ctedIndex= -1;" />
<INPUT type="checkbox" name="mycb" onclick="if(!this.checked)
this what you looking for?
<html><head>
<script>
function deSelect(selObj)
{
selObj.options[0].selected = true;
selObj.options[selObj.sele ctedIndex] .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>
<html><head>
<script>
function deSelect(selObj)
{
selObj.options[0].selected
selObj.options[selObj.sele
}
</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>
ASKER
this is my checkbox
<input type="checkbox" value="3" name="optChange3" onclick="if(this.checked)d ocument.fr mAddPositi on.selEmpL ist.disabl ed=false; else {document.frmAddPosition.s elEmpList. options[do cument.frm AddPositio n.selEmpLi st.selecte dIndex].se lected=fal se; document.frmAddPosition.se lEmpList.d isabled=tr ue;}">Edit position holder<br>
<input type="checkbox" value="3" name="optChange3" onclick="if(this.checked)d
so? call the function & make the necessary changes
ASKER
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
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