私はJavaScriptの専門家でも、アマチュアでもありません。遊んでいるスクリプトを見つけて、コード内に2番目の変数を作成する方法を考えていました。
<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);
});
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
$("select#model").attr("disabled","disabled");
$("select#type").change(function(){
$("select#model").attr("disabled","disabled");
$("select#model").html("<option>wait...</option>");
var id = $("select#type option:selected").attr('value');
$.post("select_model.php", {id:id}, function(data){
$("select#model").removeAttr("disabled");
$("select#model").html(data);
});
});
});
</script>
2番目のコードでは、カテゴリIDを取得し、$ _POST[cat_id]という別の投稿変数を作成します。同じjavacodeのselect_type.phpを参照して、これを再度行うにはどうすればよいですか?
これは、3ピースのチェーンドロップダウン用です。
ドロップ#1はドロップ#2を生成します。ドロップ#1と#2を一緒にすると、ドロップ#3が生成されます。
私が知る必要があるのは、最初のドロップダウンからそれを取得する2番目の変数を追加する方法です。
どんな助けでも大歓迎です。
編集:私はこのようなものをに追加しようとしましたが、機能しません。2番目の変数は、select_type.phpファイルのように、ドロップダウンの最初の最初の選択から取得する必要があります。または、何らかの方法で初期値を保存して持ち越し、3番目の選択を設定するのに役立てることができます。
<script type="text/javascript">
$(document).ready(function(){
$("select#model").attr("disabled","disabled");
$("select#type").change(function(){
$("select#model").attr("disabled","disabled");
$("select#model").html("<option>wait...</option>");
var carrier = $("select#type option:selected").attr('value');
$.post("select_model.php", {carrier:carrier}, function(data){
$("select#model").removeAttr("disabled");
$("select#model").html(data);
});
var countryid = $("select#category option:selected").attr('value');
$.post("select_type.php", {countryid:countryid}, function(data){
$("select#type").removeAttr("disabled");
$("select#type").html(data);
});
});
});
</script>
何か助けはありますか?