Last active
June 13, 2017 14:35
-
-
Save chukShirley/a6fe14d132fc3004d6a44c54d4190bac to your computer and use it in GitHub Desktop.
Chained select boxes populated from AJAX results
This file contains hidden or 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
<!DOCTYPE html> | |
<html class="no-js"> | |
<head></head> | |
<body> | |
<!-- Product group select box --> | |
<select name="productGroup" data-behavior="productGroup"> | |
<option value="1">1</option> | |
<option value="2">2</option> | |
</select> | |
<!-- Item code select box --> | |
<select name="itemCode" data-behavior="itemCode"></select> | |
<script type="text/javascript" src="/bower_components/jquery/dist/jquery.min.js"></script> | |
<script type="text/javascript" src="/test-reports/search/SearchTestReports.js"></script> | |
<script type="text/javascript"> | |
$(document).on('change', '[data-behavior="productGroup"]', SearchTestReports.changeProductGroup); | |
</script> | |
</body> | |
</html> |
This file contains hidden or 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
var SearchTestReports = (function () { | |
var changeProductGroup = function (event) { | |
_getItemCodesByProductGroup(event.target.value).done(function (response) { | |
// populate item code select box | |
}; | |
}; | |
var _getItemCodesByProductGroup = function (productGroup) { | |
return $.ajax({ | |
url: 'inventory/fetch-items-by-product-group', | |
dataType: 'json', | |
type: 'GET', | |
data: { | |
productGroupId: productGroup | |
} | |
}); | |
}; | |
return { | |
changeProductGroup: changeProductGroup | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment