Reputation: 738
I'm using the "Chosen" plugin to make select looks better, my question is, how could I get the selected item values in the order as they're displayed, form submit and val() all give you the values in the order of how it's being listed.
http://harvesthq.github.com/chosen/
<!DOCTYPE html>
<html><head><title></title>
<link rel="stylesheet" type="text/css" href="chosen.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript" src="chosen.jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#CheckValue').click(function() {
alert($('#test').val());
});
$('#test').chosen();
});
</script></head><body>
<?PHP if(isset($_REQUEST['test'])) var_dump($_REQUEST['test']); ?>
<form method='post'>
<select id='test' name='test[]' multiple style='width:200px;'>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
</select><br />
<input type=button id='CheckValue' value='CheckValue' />
<input type=submit value='Submit' />
</form></body></html>
Upvotes: 1
Views: 6836
Reputation: 4350
Old question I know... but I had the same question and came across this little plug-in to allow simple get / set of chosen multi-selects: https://github.com/tristanjahier/chosen-order
Upvotes: 3
Reputation: 272
just have a look at the picture and you will see a div whose id is selTJI_chzn, and inside it display some li elements. you can do just like above
$(function(){
var ret = [];
$('#selTJI_chzn').find('.search-choice').each(function(){
var selectedValue = $(this).find('span').text();
ret.push(selectedValue);
})
console.log(ret);
})
Upvotes: 3