jquery组合框+将选定值设置为组合框阵列

时间:2014-11-10 17:00:14

标签: php jquery selected

我被要求处理由其他人创建的php应用程序。

在页面中有一个表格,显示每行具有相同单元格名称的数据行 e.i:负责人[]

我想将生成的行的组合框负责[]设置为一个值,即:" name2"怎么可能做到这一点。 下面的代码生成一行的组合框。

 <?php

                        $responsibleCmb = '<td style="width:180px; min-width: 180px;" <select id="responsibles[]"
                    name="responsibles[]" style="width:180px; height:16px;">
>                   <option>-</option>';
>                   // Get all the employees that have a role id of 1 (Auditor) and display an option for each one
>                   if (isset ( $data ['employees'] )) {
>                       while ( $rowCmb = $data ['employees']->fetch_assoc () ) {
>                           // The value of the option is their employee id
>     $responsibleCmb.=          "<option value='". $rowCmb['FirstLast']. "'";
> 
>     $responsibleCmb.=                          ">$rowCmb[FirstLast]</option>";
>                       }
>                       }
>     $responsibleCmb.=          "</select></td>";
>           
>                       
>                   while ( $row = $this->data ['filtered']->fetch_assoc () ) {
>                       ?>
>                           <tr>
>                       <td style="font-size: 7.5pt; width: 60px; min-width: 60px;"><a
>                           href='<?=ROOT?>demerit/view?id=<?=$row['id']?>'>
>                                       <?=$row['id']?>
>                                   </a> <input type="hidden" value="<?=$row['id']?>" name="ids[]">
>                       </td>
>                       <td style="font-size: 8pt; width: 100px; min-width: 100px;">
>                                   <?php $description = explode(';', $row['model_main_code']);?>
>                                       <?=$description[0]?>
>                                       <hr
>                               style="margin: 0 auto; border-top-style: dashed; border-top-color: black;">
>                                       <?=$description[1]?>
>                               </td>
>                       <td><textarea class="expand" name="actions[]"><?=$row['action']?></textarea>
>                       </td>
>                            <!--               //********************************************                           --> <!--               // PRINT COMBOBOX FOR RESPONSIBLE SO THAT USER CAN'T TYPE IN A WRONG NAME.                           --> <!--
>               //******************************************** -->
>                   <?php 
>                       echo($responsibleCmb);
>                   ?>
> 
> 
> Then when i enter the td of the comobobx
> 
> <?php echo($responsibleCmb); ?>
> 
> 
> <script> $("responsibles[]").val('Doina Angheluta'); </script>

包含我的代码输出。 http://jsfiddle.net/v2quyxp3/

感谢您的帮助。

我也尝试过这种方法,而不是将组合代码存储在$ responsibleCmb变量中,但是它只会填满第一行的组合框。

                            echo '<td><select id="responsibles[]"
                                name="responsibles[]" style="width:180px;">
                                <option>-</option>';
                                // Get all the employees that have a role id of 1 (Auditor) and display an option for each one
                        if (isset ( $data ['employees'] )) {
                            while ( $rowCmb = $data ['employees']->fetch_assoc () ) {
                                // The value of the option is their employee id
                                echo "<option value='". $rowCmb['FirstLast']. "'";
                                if ($row ['responsible'] ==  $rowCmb['FirstLast']) {
                                echo ' selected=\'true\'';
                                }
                                echo ">$rowCmb[FirstLast]</option>";
                            }
                        }
                        echo "</select></td>";

0 个答案:

没有答案