Solved

deselect selected item from select box

Posted on 2003-10-28
7
1,092 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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 …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

706 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

16 Experts available now in Live!

Get 1:1 Help Now