Select box manipulation with jQuery - new plugin: selectedValues
A new plugin has been added for getting the values of options selected in a select box. More details and download from the Select Box Manipulation project page at the jQuery site.
A new plugin has been added for getting the values of options selected in a select box. More details and download from the Select Box Manipulation project page at the jQuery site.
Comments
FYI:
This plugin has a bug that causes options with duplicate values not to render.
only one of the following options will render:
var dArray = {"none":"one","none":"two"]
$("#myselect option:selected")
You should be able to get the duplicates with a slight tweak:
$.fn.selectedValues = function()
{
var v = [];
this.find("option").each(
function()
{
if(this.selected) v[v.length] = this.value;
}
);
return v;
};
Although why would have multiple options with the same value? Perhaps file this as a bug in jQuery?
http://dev.jquery.com/newticket/
var dArray = {"none":"one","none":"two"]
$("#selectBox").addOption(dArray,false);
I have test page and I can send you the url if you like.
Briefly, what I am seeing is that after calling sortOptions a call to addOptions to change the text of an existing option renames the wrong option. Please let me know if I can send you the url for the example. Thank you.
You can change values the plain jQuery way: $("#myselect").find("option[value=a]").attr("text","I am a")
Although you may still get the same problem with duplication values.