Solved

deselect selected item from select box

Posted on 2003-10-28
7
1,095 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
innerHTML 7 34
Make Session back to empty 9 30
How  can  I extract  Id  from a  URL  using  Javascript? 12 29
How do I show metrics with PHP or Javascript 6 31
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

809 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