Solved

JQuery Remove() With Select options - not removing fully

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Jquery keyup 4 20
where is team.js? 3 26
Get Pixel color of the x and y axis Html without canvas 8 36
Adding Row and Cell on a table 14 20
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…
This article discusses how to create an extensible mechanism for linked drop downs.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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 …

810 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