开发者

get values of selected items in list with jquery

开发者 https://www.devze.com 2023-03-24 03:52 出处:网络
i have one list in php page with follwoing script <div id=\'demo\' style=\"padding-left:20px\"> <select name=\'lists[]\' multiple=\'multiple\' class=\'multiselect\' >

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();

0

精彩评论

暂无评论...
验证码 换一张
取 消