• Jeff

    While I don’t know of another way to get the array of selected option texts, you can get an array of the selected values by just getting $(‘#multiplelistbox’).val().

  • Aman

    i am not getting ehich i want

    • http://www.craiglotter.co.za Craig Lotter

      And unfortunately with the changes from attr() to prop() in the new jquery 1.6 and upwards, you probably won’t ever get exactly what you want with this particular snipper :( Check out the blog on jquery.com for more information. (and don’t listen to their lies of making it backwards compatible with 1.6.1 – it isn’t fully backwards compatible any more)

  • Aman

    Hi Craig Lotteri want get all selected items in listbox jquery

    • http://www.craiglotter.co.za Craig Lotter

      Question is still a bit vague. The above code snippet should give you what you want surely?

  • http://hemantarora.com Hemant Arora

    Thanks for the nice piece of code. It greatly helped me develop the functionality I required. I tried a lot of googling but your solution was the best.
    Cheers!

    • http://www.craiglotter.co.za Craig Lotter

      Cool, glad it helped you out.

  • Shamalig

    Hi yes this does work. but I wanted this to use this to remove all selected values from the lsit box.

    $(‘#selected :selected’).each(function(i, selected) {
                     alert($(selected).val());
                    alert($(selected).text());
                   
                    $(“#selected option[value='"+ $(selected).val() +"']“).remove();
      });

    This works for all except the last value in the list box. The alert functions do work but the remove function doesn’t. can you please help me with this problem

    Regards

    • Shamalig

      sorry about the question.  There is a way to  remove all selected items.  didn’t see that earlier

  • Danfun

    Good Job.. thanks a lot.. it worked well..

Related Posts:

  • Sometimes it is nice to present a multiple select listbox to a user with everything already selected. Handy if you're using listboxes as filter controls, and something that is, as per usual, quite easy to do using the magic that is the jQuery javascript library. Essentially what the aim of the game here is to set ...

  • If you develop websites and work with JavaScript, but have never heard of jQuery before, then it is probably best that you start reading up on it right now. After all, as they like to put it themselves, jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animati ...

  • Multi-select boxes are wonderful creatures in that they provide a particularly easy to implement user interface element that provides a great deal of functionality to the end user. Today's quick code tip looks at how one would send all user's selections made in a multiple select box to a processing script using a j ...

  • To change the selected value, or selected index if you will, of a dropdown list using jQuery is not particularly difficult. The classic method to achieve this is to simply set the dropdown's value to a value already contained in the list using val(). (Of course this does require that the specified value is actua ...

  • There are a number of ways to set the selected index of a dropdown list when it comes to jQuery, though unfortunately one of them only works about half the time, basically whenever the guys behind the library remember to fix a particular bug in the system for that particular release. However, these two methods b ...

 
       

Craig Lotter is an established web developer and application programmer, with strong creative urges (which keep bursting out at the most inopportune moments) and a seemingly insatiable need to love all things animated. Living in the beautiful coastal town of Gordon's Bay in South Africa, he games, develops, takes in animated fare, trains under whichever martial arts dojo is closest at the time, and for the most part, simply enjoys life with his amazing wife and daughter.

Oh, and he draws ever now and then too.

This is a collection of things that he has managed to find the time to scribble down since 2007.

Looking for Something?

Jump to Category:

 
©2007-2013 Craig Lotter