Guest User

Untitled

a guest
Oct 19th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. $(document).ready(function () {
  2. $('#id_previous_postcode').change(function () {
  3. var postcode = $(this).val()
  4. console.log(postcode)
  5. $.ajax({
  6. // could prevent url hard coding by using url tag in form widget attribute and assign url key here to that attr
  7. url: '/users/prior_addresses_ajax/',
  8. data: {
  9. 'postcode': postcode
  10. },
  11. dataType: 'json',
  12. success: function (data) {
  13. var select = document.querySelector('#id_previous_full_address');
  14. console.log(data)
  15. data.property_choices.forEach(function (subarray) {
  16. var option = new Option(subarray[1], subarray[0]);
  17. select.options.add(option);
  18. });
  19. }
  20. })
  21. })
  22. })
Add Comment
Please, Sign In to add comment