简体   繁体   English

我如何使用jQuery从选择框中获取一堆选定的ID

[英]How can I get bunch of selected ids from select box using jquery

I am trying to get selected ids from select drop-down using jquery. 我正在尝试使用jquery从选择下拉列表中获取选择的ID。 First drop down showing project name when user select project name then it moves to another select drop-down. 当用户选择项目名称时,首先显示项目名称的下拉菜单,然后移至另一个选择下拉菜单。 and i want selected projects id also for mySql query. 我也想为mySql查询选择项目ID。 Please help how can i get bunch of ids and new drop-down create on selected base 请帮助我如何在选定的基础上获得一堆ID和新的下拉列表

Jquery code jQuery代码

     $(document).ready(function()
   {
     $("select").change(function()
       {
       var projectID=($(this).val());

  $.ajax({url:"addprojectname.php?projectID="+projectID,
    success:function(result){
   Addproject=result;
   //alert(Addproject);
  $('#selectedProject').html($('#selectedProject').html()+Addproject);
   }});});
 });

Html Code HTML代码

     <?php 
       echo  '<div id="customProject" name="customProject"
     align="center"style="width:180px;overflow-y:auto;height:205px;
     border:2px solid;display:inline-block;" >';

   $query1 = mysql_query("SELECT * from projects");

 echo '<select id="projects_ID" size="12" multiple>';

  while($r1 = mysql_fetch_array($query1))
   {
  echo  '<option value='.$r1['project_id'].'>'. $r1['Project_name'] ."</option>";

  }
  echo "</select></div>";

 echo  '<div id="selectedProject" name="selectedProject"style="width:160px;
  overflow-  y:auto;height:205px;border:0.5px
  solid;margin-left:50px;; display:inline-block;" >';
 echo '</div>';?>

Try to maintain a array like 尝试维护像这样的数组

project_id => project_name

so that u don't need to store it separately 这样您就不需要单独存储

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用jQuery从li标签获取ID? - How can i get Ids from li tags using jQuery? 如何从jQuery的选择框中获取文本? - How can I get the text from a select box with jQuery? 如何使用jQuery从选择框中清除所选值? - How do I clear the selected value from a select box using jQuery? 使用数据表通过脚本选择行以选择/选择所有行进行列出,然后如何设置/获取所选行的动态ID - using data-table for listing with select/selectall rows for rows selection by script, then how can i set/get dynamic ids of selected rows 使用jQuery选择另一个选择框的空值时,如何重置选择框? - How can i reset a select box when i select an empty value of another select box using jquery? 如何获得jQuery选择的插件来折叠选择框? - How can I get jQuery chosen plugin to collapse a select box? 如何使用jquery和select2获取选定的optgroup的值? - How can I get the value of selected optgroup with jquery and select2? 如何使用 jQuery 获取选择元素的选定选项名称或 id - How can I get the selected option name or id of a select element using jQuery 更改 jquery 中的 select 框时,如何从 while 循环中获取 id - How can i get id from a while loop when change a select box in jquery 使用jQuery在附加的选择框中获取选定的值 - Get selected value in appended select box using jquery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM