我的下拉列表存在问题。当我在下拉列表中按某些东西时,它将填满我的桌子,我没有在这里显示。但我想要的是下拉列表必须保存我按下的东西并给自己起名。我真的不知道该怎么做。
看看这个how to hold a selected list value after clicking go button?。
我的代码:
<form id="form" method="post" class="form-inline">
<div class="form-group">
<label for='Select'>head:</label>
<select class="form-control" onchange="this.form.submit()">
<?php
//My $con is someone where else.
$resultName = $con->query("SELECT * FROM ond");
while ($row = $resultName->fetch_assoc()) {
echo '<option value="'.$row["ondID"].'">'.$row['Name'].'</option>';
}
?>
</select>
</div>
</div>
</form>
答案 0 :(得分:0)
如果要为下拉列表指定名称。这是我根据上述评论理解的。
<select class="form-control" name="anyname" onchange="this.form.submit()">
<!--Rest of the code-->
</select>
答案 1 :(得分:0)
根据您的评论,我了解您希望选择下拉选项值与onchange()
事件。
function check(val)
{
alert(val);
}
<form id="form" method="post" class="form-inline">
<div class="form-group">
<label for='Select'>head:</label>
<select class="form-control" onchange="check(this.value)">
<option value="test">Test</option>
<option value="test1">Test1</option>
</select>
</div>
</div>
</form>
答案 2 :(得分:0)
请试试这个
<script>
function getDropdownVal(val){
alert(val);
}
</script>
<form id="form" method="post" class="form-inline">
<div class="form-group">
<label for='Select'>head:</label>
<select class="form-control" onchange="getDropdownVal(this.value)">
<?php
//My $con is someone where else.
$resultName = $con->query("SELECT * FROM ond");
while ($row = $resultName->fetch_assoc()) {
echo '<option value="'.$row["ondID"].'">'.$row['Name'].'</option>';
}
?>
</select>
</div>
</div>
</form>
答案 3 :(得分:0)
希望这适合你
<form id="form" method="post" class="form-inline">
<div class="form-group">
<label for='Select'>head:</label>
<select class="form-control" id="search" type="select" value="<?php echo $form-control ?>" onchange="this.form.submit()">
<option selected="selected"><?php echo "{$_POST['search']} "; ?></option>
<option>Example 1</option>
<option>Example 2</option>
<option>Example 3</option>
<?php
//My $con is someone where else.
$resultName = $con->query("SELECT * FROM `table` where `Name`");
while ($row = $resultName->fetch_assoc()) {
echo '<option value="'.$row["ondID"].'">'.$row['Name'].'</option>';
}
?>
</select>
</div>
</div>
</form>
答案 4 :(得分:0)
使用以下代码
didChangeSection
在您的代码中:
<?php $selectedValue = isset($_POST['selectName']) ? $_POST['selectName']: ""; ?>
<form id="form" method="post" class="form-inline">
<div class="form-group">
<label for='Select'>head:</label>
<select name="selectName" class="form-control" onchange="this.form.submit()">
<option value="">SELECT</option>
<option <?php if ($selectedValue=='test') echo 'selected="selected"';?> value="test">Test</option>
<option <?php if ($selectedValue=='test1') echo 'selected="selected"';?> value="test1">Test1</option>
</select>
</div>
</div>
</form>
<?php if($selectedValue) echo "You have select <strong>" . $selectedValue . "</strong>"; ?>