Deselecting An Option

Posted on 2013-05-18
Last Modified: 2013-05-23
I have a series of select boxes.  I am trying to deselect an option in one of them,  I tried this, but it does not work.  It is a single select box.

//$("#Alpha option[selected]")[0].selected = false;

Open in new window

If you select Baltimore / 1 / 13.5 Wine Bar  Then go back and select another city you will see that the filter box remains selected.
Question by:DS928
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Author Comment

ID: 39177453
Tried this, and it does not work as well.
$("#Alpha").selectedIndex = -1;

Open in new window

LVL 82

Accepted Solution

leakim971 earned 500 total points
ID: 39177519


Author Comment

ID: 39177537
Thank you.  Yes it works, also deselects immediately as opposed to deselecting when the city is selected.

$(document).ready(function() {
			$('#City, #Alpha').change(function() {
			//get the values
			city = ($('#City').val());
			alpha = ($('#Alpha').val());

			//if both values are set, fire the ajax call
			if (city && alpha) {
				type: "POST",	
				url: "../Scripts/alpha_search.php",
				data: {"Letter": alpha, "Cid": city},
				success: function (html) {
		} else {
			$("#RestMenus option").remove();

Open in new window


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Video Tutorial help 2 50
15 puzzle in Javascript/html 2 86
Slush on text 2 25
What kind of script/language created this graph? 6 59
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

739 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