Solved

deselect selected item from select box

Posted on 2003-10-28
7
1,093 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:James Rodgers
  • 3
  • 2
  • 2
7 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 30 total points
ID: 9635471
that should work, but you may try this:

selObj.focus();
selObj.selectedIndex =- 1;
selObj.blur();
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9635476
... but I suspect something else is going on.  Can you show us the code you are using on the checkbox to deselect the item?
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9635483
should be something like this:

<INPUT type="checkbox" name="mycb" onclick="if(!this.checked)this.form.nameOfTheSelect.selectedIndex=-1;" />
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9635507
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>
0
 
LVL 25

Author Comment

by:James Rodgers
ID: 9635573
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>
0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9635589
so? call the function & make the necessary changes
0
 
LVL 25

Author Comment

by:James Rodgers
ID: 9635779
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now