Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JQuery Remove() With Select options - not removing fully

Posted on 2012-03-14
2
Medium Priority
?
217 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

618 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