【问题标题】:check checkbox on populated dropdown value selection [SQL-SERVER]选中填充下拉值选择 [SQL-SERVER] 上的复选框
【发布时间】:2019-05-25 15:38:53
【问题描述】:

这个例子有 8 个复选框:

 <table style="border-collapse: collapse; width: 100%;" border="1">
    <tbody>


    <tr style="height: 21px;">
    <td style="width: 25%; height: 21px;"><strong>Technologie</strong></td>
    <td style="width: 25%; height: 21px;"></td>
    <td style="width: 25%; height: 21px;"></td>
    <td style="width: 25%; height: 21px;"></td>
    </tr>
    <tr style="height: 21px;">
    <td style="width: 25%; height: 21px;">Tec1</td>
    <td style="width: 25%; height: 21px;">  <input name="Technologie[Tec1]" type="checkbox" value="1" /> </td>
    <td style="width: 25%; height: 21px;">Tec2</td>
    <td style="width: 25%; height: 21px;"><input name="Technologie[Tec2]" type="checkbox" value="1" /></td>
    </tr>
    <tr style="height: 21px;">
    <td style="width: 25%; height: 21px;">Tec3</td>
    <td style="width: 25%; height: 21px;">  <input name="Technologie[Tec3]" type="checkbox" value="1" /> </td>
    <td style="width: 25%; height: 21px;"Tec4</td>
    <td style="width: 25%; height: 21px;">  <input name="Technologie[Tec4]" type="checkbox" value="1" /> </td>
    </tr>
    <tr style="height: 21px;">
    <td style="width: 25%; height: 21px;">Tec5</td>
    <td style="width: 25%; height: 21px;">  <input name="Technologie[Tec5]" type="checkbox" value="1" /> </td>
    <td style="width: 25%; height: 21px;">Tec6</td>
    <td style="width: 25%; height: 21px;">  <input name="Technologie[Tec6]" type="checkbox" value="1" /> </td>
    </tr>
    <tr style="height: 21px;">
    <td style="width: 25%; height: 21px;"></td>
    <td style="width: 25%; height: 21px;">Tec7</td>
    <td style="width: 25%; height: 21px;">  <input name="Technologie[Tec7]" type="checkbox" value="1" /> </td>
   <td style="width: 25%; height: 21px;">Tec8</td>
    <td style="width: 25%; height: 21px;">  <input name="Technologie[Tec8]" type="checkbox" value="2" /> </td>

    </tr>
    </tbody>
    </table>

这是填充下拉列表的 SQL 表:

+--------+------+------+------+------+------+------+------+------+------+
| Tec_ID | Tec1 | Tec2 | Tec3 | Tec4 | Tec5 | Tec6 | Tec7 | Tec8 |RanNr |
+--------+------+------+------+------+------+------+------+------+------+
|      1 |    1 |    0 |    0 |    0 |    1 |    0 |    0 |    0 | 1353 |
|      2 |    1 |    0 |    0 |    0 |    0 |    1 |    0 |    0 | 0000 |
|      3 |    1 |    0 |    0 |    0 |    0 |    0 |    1 |    1 | 1353 |
|      4 |    1 |    1 |    1 |    0 |    1 |    0 |    0 |    0 | 1123 |
|      5 |    1 |    1 |    1 |    0 |    0 |    1 |    0 |    2 | 1353 |
|      6 |    1 |    1 |    1 |    0 |    0 |    0 |    1 |    2 | 1353 |
|      7 |    0 |    0 |    0 |    1 |    0 |    0 |    0 |    1 | 1993 |
|      8 |    0 |    1 |    1 |    0 |    1 |    0 |    0 |    0 | 1123 |
|      9 |    0 |    1 |    1 |    0 |    0 |    1 |    0 |    0 | 1353 |
|     10 |    0 |    0 |    0 |    0 |    0 |    0 |    0 |    2 | 1366 |
+--------+------+------+------+------+------+------+------+------+------+

这里是我如何填充下拉列表的 PHP 部分。

<select id="Tec_ID" name="Tec_ID" size="1" >    
                    <option disabled selected value> </option>;

            <?php
            foreach($connection->query($tec) as $m)
            {
                        if($m['Tec_ID'] == $_GET['Tec_ID']){
                $isSelected = 'selected="selected"';
            }else{
                $isSelected = '';
            }
            echo "<option value='" . $m['Tec_ID'] . "'".$isSelected."  >" .$m['RanNr'] ."</option>";
            }
            ?> 

注意最后一个 Tec8 可以是 1 或 2。

例如。如果我选择 Tec_ID 1,您已经看到了。应该选中 Tec1 和 Tec5 复选框。

但是 atm 我不知道,如何使用 Javascript/PHP/MSQLCode 处理这个问题?有人可以帮忙吗?

【问题讨论】:

    标签: javascript php html sql-server checkbox


    【解决方案1】:

    我使用您提供的信息创建了以下 PHP 演示:http://sandbox.onlinephpfunctions.com/code/1ffa32dbd5fd7db48057c0b7fa82cbd9d23b34ce

    它生成了以下 HTML (https://codepen.io/anon/pen/joxBbL):

    <select id="Tec_ID" name="Tec_ID" size="1" >    
        <option disabled selected value> </option>;
    
        <option value='1'  >1353</option>
        <option value='2'  >0</option>
        <option value='3'  >1353</option>
        <option value='4'selected="selected"  >1123</option>
        <option value='5'  >1353</option>
        <option value='6'  >1353</option>
        <option value='7'  >1993</option>
        <option value='8'  >1123</option>
        <option value='9'  >1353</option>
        <option value='10'  >1366</option>
    </select>
    

    我不确定您想要完成什么,但每个$tecRanNr 变量都有一个下拉列表

    (我没有足够的代表发表评论,但我稍后会编辑/删除这个答案)

    【讨论】:

    • 是的,但我使用来自我的 SQL-Server 的 SQL 查询填充下拉列表。我写了,我不能为每个条目做数组。我不知道你发布了什么?我问当我选择例如第一个条目时,应选中复选框 1 和 5。
    猜你喜欢
    • 2016-09-03
    • 2019-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-24
    相关资源
    最近更新 更多