Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
27
rated 0 times [  29] [ 2]  / answers: 1 / hits: 113902  / 12 Years ago, wed, february 20, 2013, 12:00:00

I have problem in get all selected option in multi select



<select multiple= title= class= id=fm_delivery_or_collection name=fm_fields[fm_delivery_or_collection][]>
<option value=90>Delivery or Collection1</option>
<option value=91>Delivery or Collection2</option>
<option value=92>Delivery or Collection3</option>
</select>


Bellow is my code and its return me only first selected option



var select = form.find('select')

for (var i = 0; i < select.length; i++)
{
var s_id = jQuery(select[i]).attr('id');
var str=,i;

var e = document.getElementById(s_id);
var strUser = e.options[e.selectedIndex].text;

var name = jQuery(select[i]).attr('name')
var str1 = jQuery(select[i]).attr('id').replace(fm_, )
requestString += <b>+str1.replace(/_/g, )+</b> + ':' +strUser+<br>;
}


So please suggest me how can i get all selected option text and where I make mistake ?


More From » jquery

 Answers
18

Your comment please suggest me how can i get all selected option text, So you can try this:



$(#fm_delivery_or_collection option:selected).each(function () {
var $this = $(this);
if ($this.length) {
var selText = $this.text();
console.log(selText);
}
});

[#80114] Tuesday, February 19, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jazmyne

Total Points: 503
Total Questions: 102
Total Answers: 99

Location: Svalbard and Jan Mayen
Member since Sun, Sep 25, 2022
2 Years ago
;