问问题
479 次
1 回答
3
在您的 php 页面上的 $_POST 变量下获取您的选择,同时添加method = "post"
您的表单。
例如。$_POST['forward'] 将在此页面上的此表单中提供转发选择时选择的选项!
更新:
你的表格
<form name="myform" action="selectPlayer.php" method = "post">
<select name="forward" id="forward">
<option value="-">-------</option>
<option id="forwardAdd" value="add">Add</option>
<option id="forwardChange" value="change">Change</option>
</select>
<input type="submit" name="submit" value="Submit">
</form>
选择播放器.php
<?php
if(isset($_POST['forward'])){
echo "OK";
}
?>
更新 2:
重要的是将 jquery 文件附加到您的 form.php
表单.php
<html>
<head>
<script src="jquery-1.9.0.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
$(document).on('change', '#name', function() {
//var element = $(this); //USE THESE IN CASE OF MULTIPLE IDENTICAL FORMS AFTER MANIPULATING
//var id = element.attr("id");
var option = $("#name").val(); //obtaining the selected value
var dataString = 'name='+ option; //preparing the datastring to send to get.php
$.ajax({ //using ajax
type: "POST", //request type post, you can use get here
url: "get.php", //page you're sending request
data: dataString, //datastring you are passing
dataType:'html', //responsetype you are wanting
cache: false,
success: function(data){ //in case of successful response from get.php, response is in dataType format inside variable "data"
$("#output").append(data); //doing stuff on this page from response received from get.php
}
});
return false;
});
});
</script>
<form>
<select id="name">
<option >---</option>
<option value="1">ONE</option>
<option value="2">TWO</option>
<option value="3">THREE</option>
</select>
</form>
<div id="output">THINGS WILL COME HERE, DELETE THIS TEXT IN ACTUAL USE<br/></div>
</body>
</html>
获取.php
<?php
if(isset($_POST['name'])){
switch($_POST['name']){
case '1': echo "YOU HAVE SELECTED ONE<br/>";
break;
case '2': echo "\nYOU HAVE SELECTED TWO<br/>";
break;
case '3': echo "\nYOU HAVE SELECTED THREE<br/>";
break;
default : break;
}
}
?>
于 2013-05-07T06:15:01.133 回答