简体   繁体   English

在PHP / HTML中的方法“ post”之后获取所选下拉列表的值

[英]Get value of selected dropdown after method “post” in PHP/HTML

im trying to get the value of a selected dropdown my code looks like this: 我试图获取所选下拉列表的值,我的代码如下所示:

 echo "<form action='trylog.php' method='post'>";
    echo "<div class='custom-select'>";
    echo "<select name='gymnasier'>";

foreach($schools as $x => $x_value) {
    echo "<option>";
    echo "$x"; 
    echo "</option>";

}
echo "<br></option></select>";
echo "<input type='text' id='lectioid' name='lectioid' placeholder='Dit Lectio ID'>";
echo "<input type='submit'>";
echo "</div></form>"

So what this does is get the name of "gymnasier" which in this case is the highschool name, however what i want to get is: "$x_value". 所以这样做是得到“ gymnasier”的名称,在这种情况下是高中名称,但是我想要得到的是:“ $ x_value”。 But i would like to make people choose the name in the dropdown and i will receive the ID after method "post", in my other php file "trylog.php", instead of the highschool name. 但是我想让人们在下拉列表中选择名称,我将在其他php文件“ trylog.php”中的方法“ post”之后收到ID,而不是高中名称。 "$x". “ $ x”。

Every option tag can have value attribute, which is paased to server: 每个option标签都可以具有value属性,该属性将被赋给服务器:

echo "<select name='gymnasier'>";

foreach($schools as $x => $x_value) {
    echo '<option value="' . $x . '">';
    echo $x_value; 
    echo "</option>";
}

echo "</select>";    // `<br></option>` is useless

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM