Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function () {
- $('#id_previous_postcode').change(function () {
- var postcode = $(this).val()
- console.log(postcode)
- $.ajax({
- // could prevent url hard coding by using url tag in form widget attribute and assign url key here to that attr
- url: '/users/prior_addresses_ajax/',
- data: {
- 'postcode': postcode
- },
- dataType: 'json',
- success: function (data) {
- var select = document.querySelector('#id_previous_full_address');
- console.log(data)
- data.property_choices.forEach(function (subarray) {
- var option = new Option(subarray[1], subarray[0]);
- select.options.add(option);
- });
- }
- })
- })
- })
Add Comment
Please, Sign In to add comment