javascript - JQM: how to get (only 1) selected item (on select/click) from a SELECT (multiple)? -


edit : since im new jqm , did not find easy (jqm built-in) way keep(retain) orders upon selecting items multiple , broke down algo in mind , think need meet question below, can users ranked picks among items @ . ps prefer jqm way as possible.

main issue : how can selected item (only 1)? since multiple, both $(this).val() , $(this).text() fails, after..

<select name="names[]" multiple="multiple" data-native-menu="false">`   <option>opt1</option>   <option>opt2</option>   <option>opt3</option> </select> 

i have jquery :

$('body').delegate('select','change',function(e) {   //selected_or_clicked_item = $(this).val();   //after selecting multiple item - returns array of input ['opt1','opt3','opt2']   selected_or_clicked_item = $(this).text(); // returns concatenated options text - opt1opt2opt3 }); 

i right item @ first selection (ex. opt1), after second selection (opt2) both instead (['opt1','opt2'] or opt1opt2)

try

$('body').delegate('select','change',function(e) {       //selected_or_clicked_item = $(this).val();       //after selecting multiple item - returns array of input ['opt1','opt3','opt2']       selected_or_clicked_item = $(this).find('option:selected').text(); // returns concatenated options text - opt1opt2opt3     }); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -