单击一个特定的单选按钮或选择选项后,我想添加一个文本输入我有一个表单,其中有两个部分,其中单击“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>
1 回答

蝴蝶不菲
TA贡献1810条经验 获得超4个赞
您可以在您的选择下添加:
<input type="text" id="sonstiges" hidden>
并在您的脚本中:
$('#gtyp').change(function(){
var optionSelected = $('#gtyp option').filter(':selected').text();
if(optionSelected == "Sonstiges"){
$('#sonstiges').toggle();
}
});
- 1 回答
- 0 关注
- 127 浏览
添加回答
举报
0/150
提交
取消