Last active
May 3, 2017 11:50
-
-
Save RakibSiddiquee/90a0a4069dbce35cad5e45fe00447755 to your computer and use it in GitHub Desktop.
Populate one dropdown when select another dropdown. You must include the jquery file top of your code...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// There are two ways... | |
// No:1....... | |
$(function() { | |
$('#category').change(function() { | |
var cat = $(this).val(); | |
$.get('{{ url("categories") }}', {'cat_id': cat}, function (data) { | |
$('#subcategory').empty(); | |
$.each(data, function(key, value) { | |
$('#subcategory').append("<option value='"+ value.id +"'>" + value.name + "</option>"); | |
}); | |
}); | |
}); | |
}); | |
// No:2............ | |
$('#upozilla').prepend('<option value="1" selected>--None--</option>'); | |
$('#district').on('change', function(e){ // Pre-populate upozilla with selecting district dropdown | |
console.log(e); | |
var district_id = e.target.value; | |
$('#upozilla').empty(); | |
$.get('{{ url("/upozilla-populate?district_id=") }}'+district_id, function(data){ | |
$.each(data, function(index, upozillaObj){ | |
$("#upozilla").empty(); | |
$('#upozilla').append('<option value="'+upozillaObj.id+'">'+upozillaObj.upozilla_name_bn+'</option>'); | |
}); | |
$('#upozilla').prepend('<option value="1" selected>--None--</option>'); | |
}); | |
}); | |
// Then get the cat_id or district_id in php file and select data and return the data in json format | |
// In laravel get the id in your controller and return the data in json format |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes sir, this is a cascading select functionality in html format. but, I will need your help to apply this in laravel. I read the last line but yet this too complex to me. .... ;-)