Solved

JQuery Remove() With Select options - not removing fully

Posted on 2012-03-14
2
206 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 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course 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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

691 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