单击一个特定的单选按钮/选择选项后添加一个文本字段

单击一个特定的单选按钮或选择选项后,我想添加一个文本输入


我有一个表单,其中有两个部分,其中单击“Sonstiges”(德语为“其他”)应该显示或添加附加文本输入,用户可以在其中为自己添加一些内容我找不到解决方案。我能找到的唯一方法是通过 ajax 添加动态输入量。但为此,我只需要一个固定数量。所以我想知道是否有更简单或更优雅的方法。


应该发生的地方


<h2>Problem & Geräteauswahl</h2>

        <?php


            //Einbinden der Datenbankverbindung

            include 'dbconfig.php';


            //Auslesen aller Gerätetypen

            $query = $db->query("SELECT * FROM typ ORDER BY name ASC");


            //Auslesen der Zeilen

            $rowCount = $query->num_rows;

        ?>  


            <label for='gtyp'> Gerätetyp:

            <select name = 'gtyp' id = 'gtyp'>

            <option>Bitte Auswählen</option>


        <?php

            if($rowCount > 0){

                while($row =  $query->fetch_assoc()){

                    echo '<option value="'.$row['typ_ID'].'">'.$row['name'].'</option>';

                }

            } else{

                echo '<option>Wenn sie das sehen, hat Chris seinen Job nicht gut gemacht</option>';

            }

            ?>

            <option>Sonstiges</option>

            </select>

            </label>


        <br>

            <label for = 'hers'> Hersteller:

            <select name = 'hers' id= 'hersteller'>

                <option>Bitte Gerätetyp wählen</option>

            </select>

            </label>

        <br>

            <label for = 'ger'> Gerätebezeichnung:

            <select name = 'ger' id= 'geraet'>

                <option>Bitte Hersteller wählen</option>

            </select>

            </label>


        <br>

        Add Testfield here

        <br>


翻过高山走不出你
浏览 128回答 1
1回答

蝴蝶不菲

您可以在您的选择下添加:<input type="text" id="sonstiges" hidden>并在您的脚本中:$('#gtyp').change(function(){&nbsp; var optionSelected = $('#gtyp option').filter(':selected').text();&nbsp; if(optionSelected == "Sonstiges"){&nbsp; &nbsp; $('#sonstiges').toggle();&nbsp; }});
打开App,查看更多内容
随时随地看视频慕课网APP