Issue
Hi All please suggest me some approaches for the below problem Spring boot MVC: UI page is JSP Currently All dropdown values are getting from DB when the home page is opened I am stuck at the below task On selection of one dropdown value, the below other dropdown values should be auto populated in jsp before the form is submitted How do I make a GET request on selection of one dropdown value and get data for other dropdowns from DB? below is the sample jsp form enter image description here
Solution
if you using jquery with jsp then , use Ajax POST in Change event of name-3 dropdown , on success function populate on name-4 , name-5 drop down.
Like,
$(document).on('change','#name3',function(){
callAjaxByObj({
"url" : "url",
"type" : "POST",
"data" : {"name3Id" : $(this).val()},
"resp" : afterSuccess(),
"error" : ajaxFailed()
});
});
function afterSuccess(){
return function(resp){
// here you can populate Selected data on name-4, name-5 dropdowns use below
$("#name4").val(resp.name4Id);
$("#name5").val(resp.name5Id);
// OR if you want to append new drop down values to append name4, name5 dropdowns
var htm='';
var index = 0;
var obj = '';
for(index = 0; index < resp.name4List.length; index++) {
obj = resp.name4List[index];
htm +='<option value="'+obj.id+'" >'+obj.name+'</option>';
}
$("#name4").append(htm);
// same way you can do for name5 drop down.
}
}
Answered By - K Kishore Kumar Reddy