get values of selected items in list with jquery
i have one list in php page with follwoing script
<div id='demo' style="padding-left:20px">
<select name='lists[]' multiple='multiple' class='multiselect' >
<?php
$sql="select list_id,list_name from tbl_list";
$result=mysql_query($sql);
for($i=1;$i<=mysql_num_rows($result);$i++)
{
$row=mysql_fetch_array($result);
?>
<option value='<?php echo $row['list_id']; ?>' title='<?php echo $row['list_name']; ?>'><?php echo $row['list_name']; ?></option>
<?php
}
?>
</select>
</form>
</div>
now after i select multiple rows in list box, i want to get 开发者_运维技巧the values of selected rows with jquery.
Thanks
$('select').val();
will return your selected values in the form x,y,z
$('select').val();
to get the value of the select at that time
$('select').change(function(){
alert($(this).val());
});
To get it every time it is changed.
Example for multiple selects on a page: http://jsfiddle.net/Mxtey/
Hope this helps
try $("select").serialize();
and it probably give you exactly what you want
however there should be "form" first and after that you should use
$("form").serialize();
精彩评论