What does your console say, regarding this
? I believe the issue may be that $(this)
inside of $.post
refers to the window
object, and not to #zip
. A couple other notes, too:
- What it looks like you're attempting to do is send whatever value
#zip
has, which is an input
element referring to the postcode (not to the suburb).
Since the select
is going to be loaded dynamically, old handlers no longer apply. However, you can delegate, like so:
$(document).on('blur','#suburb',function() {
//do whatever
});
As far as context issues go for this
, I believe $.post
callbacks are called in the context of the window
. Try this to fix that issue, perhaps:
$("#zip").on('blur',function(){
var self = this;
$.post("get_suburb_admin1.php",{zip:$(self).val()}, function(d){
$("#suburb_cnt").html(d);
});
});
Overall it appears there could be several potential issues with your code, and with what you are trying to do. I recommend you search for more information regarding AJAX, JavaScript function context, and jQuery selectors.
Side note: you may want to reconsider how you are loading the select
with your php, unless you are committed to it for a good reason. Testing the webpage myself, it took almost 10 seconds at times for the select
to load from your AJAX call.