Solved

JQuery Remove() With Select options - not removing fully

Posted on 2012-03-14
2
199 Views
Last Modified: 2012-03-14
Hi All,

I am using the JQuery.remove() to remove option elements from a html SELECT list as per the following code...

WHat I am finding is that even though I have removed certain list items, when you click on  the remaining items, it's value appears to be the value of a removed item if that make sense??... try clicking on the item Porsche and you will see the alert() is Audi.

http://jsfiddle.net/rit01/9cWAS/

Can anyone suggest a fix for this?

Many thanks,

Rit

HTML
<select multiple="multiple" id="cars">
    <option value="volvo" title="01/05/2011">Volvo</option>
    <option value="saab" title="01/15/2011">Saab</option>
  <option value="opel" title="04/06/2011">Opel</option>
  <option value="audi" title="05/04/2011">Audi</option>
    <option value="audi" title="01/04/2011">Porsche</option>
</select>

Open in new window


JS
function refineList(fromDateArg, toDateArg) {

    $("#cars > option").each(function() {

        optionDate = $.datepicker.formatDate("mm/dd/yy", new Date(this.title));
        fromDate = $.datepicker.formatDate("mm/dd/yyyy", fromDateArg);
        toDate = $.datepicker.formatDate("mm/dd/yyyy", toDateArg);

        if (!(optionDate >= fromDate && optionDate <= toDate)) {
            $(this).remove();
        }
    });
}

refineList(new Date("01/01/2011"), new Date("03/31/2011"));

$("#cars > option").click(function(){
    alert($(this).val());
});

Open in new window

0
Comment
Question by:rito1
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 37722842
I see :

<option value="audi" title="01/04/2011">Porsche</option>
0
 
LVL 1

Author Closing Comment

by:rito1
ID: 37723580
Ha ha! What an idiot I am! Brilliant ;-)
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article will show, step by step, how to integrate R code into a R Sweave document
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

760 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

20 Experts available now in Live!

Get 1:1 Help Now