イム次の2つのドロップダウン選択を持っているので、あなたは何を意味するか確認してください、しかし、私の理解に基づいて、
ない、 いずれかを選択し、第二子が選択され、 子供がドロップダウンの値を選択するには、依存します親の選択、 はそれがあなたが意味するものですか?
それは、これを実行するための簡単な方法
であれば、jQueryとAJAXを使用することで、
あなたがこれを行うには、基本的なAJAXとイベントリスナーを読まなければならない、
第一選択のドロップダウン、
<select id="parent_select">
</select>
<select id="child_select">
</select>
/*これはあなたの親が選択移入します*/
$.ajax({
url: 'url that will display all list'
dataType: 'json',
type: 'get',
success: function(data){
var output = "";
$.each(data, function(a,b){
output += "<option value='"+b.id+"'>"+b.parent_select_name+" </option>"
$("#parent_select").append(output);
});
}
})
/*これは、あなたの子供はあなたが `ajax`と` jquery`または `javascript`を使用する必要があなたの親*/
$(document).on("change", "#parent_select", function(){
var parent_id = $(this).attr("id");
$.ajax({
url: 'url that will display child data where parent_id = parent_id ',
type: 'POST',
dataType: 'json',
data: { 'parent_id' : parent_id } /* you are passing parent_id*/
success: function(data){
$("#child_select").empty();
var output = "";
$.each(data, function(a,b){
output += "<option id="+b.child_id+">"+b.child_desc+"</option>";
})
$("#child_select").append(output);
}
})
})
の値を変更するときに選択し移植します。この[リンク]を確認してください(https://stackoverflow.com/questions/11237900/first-drop-down-menu-to-auto-change-the-options-of-a-second-dropdown) –
ありがとうございました。 –
ページのリロード時に[選択されたドロップダウンメニューを動的に使用して別のドロップダウンを変更するなど]の可能な複製(https://stackoverflow.com/questions/45705095/selected-drop-down-dynamically-using-javascript-when-ページリロードおよび変更予定) – Gagantous