用户从选择框中选择的选项,它必须被发送到所需的php文件(getStatus.php)可以使用get方法或post方法
但不使用表单提交按钮
<select name="status">
<option value="step_1">step_1</option>
<option value="step_2">step_2</option>
<option value="step_3">step_3</option>
</select>
<a href="getStatus.php"> Go </a>
您将有一个名为$_POST['status']
或$_GET['status']
的变量,其值等于所选option
的值。没有更多的代码,这就是我能告诉你的。
编辑:这将需要在form
中进行,action
属性设置为getStatus.php
,最好使用POST
方法。如果您想将数据传递到另一个页面,除非使用AJAX传递数据,否则没有任何方法可以使用表单。为什么表单不是一种选择?
使用javascript
:-
<select name="status" id="myselect">
<option value="step_1">step_1</option>
<option value="step_2">step_2</option>
<option value="step_3">step_3</option>
</select>
<a href="#" onclick="click_me()"> Go </a>
<script>
function click_me(){
var selects = document.getElementById("myselect");
var selectedValue = selects.options[selects.selectedIndex].value;// will gives u 2
var selectedText = selects.options[selects.selectedIndex].text;// gives u value2
window.location = "getStatus.php?id="+selectedText;
}
</script>
<select name="status" id="status">
<option value="step_1">step_1</option>
<option value="step_2">step_2</option>
<option value="step_3">step_3</option>
</select>
<a href="#" onclick="getitem()"> Go </a>
<script>
function getitem(){
var item = document.getElementById('status').value;
location.href="getStatus.php?id="+item;
}
</script>