gpt4 book ai didi

php - 将选定的选项值从 select 传递到 php

转载 作者:太空狗 更新时间:2023-10-29 15:41:42 26 4
gpt4 key购买 nike

    <style type="text/css">
form select {
display:none;
}
form select.active {
display:block;
}
</style>
<script type="text/javascript">
window.onload = function () {
var allElem = document.getElementsByName("sl");
for (i = 0; i < allElem.length; i++) {
allElem[i].addEventListener('change', toggleDisplay);
}
}
function toggleDisplay(e) {
var id = 's' + this.value;
var currentSelect = document.getElementsByClassName("active")[0];
if (currentSelect) {
currentSelect.className = "";
}
document.getElementById(id).className = "active";
}
</script>
</head><body>
<form action="check_a.php">
<h2><b>Source: </b></h2>
<input type="radio" name="sl" value="c">Central</input>
<input type="radio" name="sl" value="h">Eastern</input>
<input type="radio" name="sl" value="w">Western</input>

<select id="sc" name="sc">
<option value="1">1</option>
<option value="2">2</option>
</select>

<select id="sh">
<option value="3">3</option>
<option value="4">4</option>
</select>

<select id="sw">
<option value="5">5</option>
<option value="6">6</option>
</select>
<input type="submit" name="submit" value="submit"/>

</form></body></html>

有一个单选按钮,其值显示特定的选择框,这是使用 javascript 完成的。标签的值需要传递给 php 代码。如何将选定的选项值传递给 php?

最佳答案

你不能把所有的 select 元素都设置成同名吗?

<select id="sc" name="tagvalue">
<option value="1">1</option>
<option value="2">2</option>
</select>

<select id="sh" name='tagvalue'>
<option value="3">3</option>
<option value="4">4</option>
</select>

<select id="sw" name='tagvalue'>
<option value="5">5</option>
<option value="6">6</option>
</select>

然后,取$_POST['tagvalue']的值。

关于php - 将选定的选项值从 select 传递到 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17465455/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com