在另一个下拉列表中选择一个选项填充一个下拉列表 [英] Populate a dropdown on selecting an option from another dropdown Laravel
问题描述
希望您今天过得愉快,我很清楚地描述了我的问题:)
Hope you're having a nice day and i'm much clear to describe my problem :)
我有一个类别表和一个子类别表.在我看来,我想让用户选择一个属于某个类别的子类别,以添加一个产品(每个产品都属于一个子类别).为此,我想在用户选择类别时显示他的子类别.就像他从类别"中选择衣服"一样,我想显示诸如上衣,短裤等子类别.
I have a table of categories and a table of sub-categories. In my view, I want to let the user select a sub-category belonging to a category, for adding a product (Every product belongs to a sub-category). For that purpose, I want to show the user sub-categories when he selects a category. Like when he selects Clothes from Categories, I want to show Sub-categories like tops, shorts etc.
我该怎么做?只是一个主意就行.
How do I do that? Just an idea would work.
谢谢.
推荐答案
尝试一下
在第一个下拉列表onchange中调用getjson并将所选值传递给url,并在第二个下拉列表中加载结果.希望这对您有帮助
call getjson in first dropdown onchange and pass the selected value to url and load the results in second dropdown . Hope this helps you
$(document).ready(function(){
$( "#firstdropdown" ).change(function() {
var firstdropselectedvalue= $("#firstdropdown").val();
var url= test.php?selected=firstdropselectedvalue;
$.getJSON(url, function(data){
$.each(data, function(index, text) {
$('#seconddropdown').append(
$('<option></option>').val(index).html(text);
);
});
});
});
});
这篇关于在另一个下拉列表中选择一个选项填充一个下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!