[英]how to generate dynamic textboxes based on user input in php/javascript?
This code below is displaying data through a dropdown and I was wondering on how can I convert this into like a when a user enters a number in a textbox and click set, dynamic dropdowns appear based on the number he entered. 下面的代码通过一个下拉列表显示数据,我想知道当用户在文本框中输入数字并单击“设置”时,如何将其转换为类似的形式,动态下拉列表将基于他输入的数字出现。
$query = mysqli_query($con, "SELECT * FROM topic WHERE SubCat = $subcat ");
echo "<select name='topdd' >";
echo " <option>--None Selected--</option>";
while ($row = mysqli_fetch_array($query)) {
echo "<option value='$row[topic_id]' selected>";
echo $row["title"];
echo "</option>";
}
echo "</select>";
This code it's ok for you ? 此代码适合您吗? I make your job, the next time try yourself 我做你的工作,下次再试
<form method="POST">
<label for='choiceNumber'>Number of dropdowns choice</label>
<input type='number' name='choiceNumber'>
<input type='submit'>
</form>
<?php
$resultArray = array(1,2,3,4,5,6,7);
$display = "<select name='topdd'><option>--None Selected--</option>";
if (!empty($_POST['choiceNumber']) && $_POST['choiceNumber'] > 0) {
for($i = 0; $i < $_POST['choiceNumber']; $i++) {
$display .= "<option>".$resultArray[$i]."</option>";
}
}
echo $display."</select>";
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.