I have two dropdowns to fill up by applying the following cases:
- Fill the the first dropdown with all the folder names (done by using
Fileclass). - Fill the second dropdown with the subfolder names which is now based on the first dropdown.
So my jQuery part is:
$('#rootFolder').change(function() {
var rootFoldervalue = $(this).options[$('#rootFolder').selectedIndex];
How do I send this selected rootFolder value to my JSP page so that i can again calculate the subFolder names and show it in the second dropdown?
getsubfolder.jsp
<%
String root = request.getParameter("foldername");
String path = "G:\\ANDROID\\";
File rootFile = new File(path);
File[] listOfDirs = rootFile.listFiles();
out.println(listOfDirs);
%>
jQuery part:
$(document).ready(function() {
$("#rootFolder").change(function() {
var rootFolderValue = $('#rootFolder').val();
$.ajax({
url: 'getsubfolder.jsp',
data:'foldername=' + rootFolderValue,
dataType: 'json',
success:function(data) {
$.each(data, function(i, data) {
$('#subFolder').append(
$('<option></option>').val(data.Value).html(data.Text)
)});
}
});
Transferring file array as a JSON is not working. How do I manipulate the values received in the data of success part of $.ajax() to populate my second dropdown?