?
Solved

JQuery Remove() With Select options - not removing fully

Posted on 2012-03-14
2
Medium Priority
?
213 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
[X]
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 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

764 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