嘿,我有这个链式选择。来源:http://www.yourinspirationweb.com/en/how-to-create-chained-select-with-php-and-jquery/
我得到了它的工作,但我发布选定的结果有一些问题。谁能帮我。我从数据库中获取主要和子类别。当我尝试将它发送到post.php我得到未定义的索引。我怎样才能将变量从java发布到php。任何帮助将不胜感激。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("select#type").attr("disabled","disabled");
$("select#category").change(function(){
$("select#type").attr("disabled","disabled");
$("select#type").html("<option>wait...</option>");
var id = $("select#category option:selected").attr('value');
$.post("select_type.php", {id:id}, function(data){
$("select#type").removeAttr("disabled");
$("select#type").html(data);
});
});
$("form#select_form").submit(function(){
var cat = $("select#category option:selected").attr('value');
var type = $("select#type option:selected").attr('value');
if(cat>0 && type>0)
{
var result = $("select#type option:selected").html();
$.ajax({
data: result,
url: 'post.php',
method: 'POST', // or GET
success: function(msg) {
alert(msg);
}
});
}
else
{
$("#result").html("you must choose two options!");
}
return false;
});
});
</script>
</head>
<body><p>
<?php include "select.class.php";
?>
<form id="select_form" action="post">
Choose a category:<br />
<select id="category">
<?php echo $opt->ShowCategory(); ?>
</select>
<br /><br />
Choose a type:<br />
<select id="type">
<option value="0">choose...</option>
</select>
<br /><br />
<input type="submit" value="confirm" />
</form>
<div id='result'></div>
</body>
</html>
Post.php
<?php
echo $_POST['result'];
?>