I have JQuery code on a web page that pulls data from a php function in JSON format. The code executes only after I click the button twice. In the chrome dev tools I see this error for the first button push: Uncaught TypeError: Cannot read property 'number' of undefined
// JSON Data example:
{
"number": "555",
"street": "S La Veta Park Cir",
"propertynumber": "",
"city": "Orange",
"state": "CA",
"zip": "92868"
}
// Script
var address;
var propertyinfo;
$('.step1').siblings().hide(); // hide all except step 1
$('.search').click(function(){
var filledaddress = $('#address').val();
$.get("addresslibrary.php?command=parse&address="+filledaddress, function(addressdata){
address = JSON.parse(addressdata);
});
$('#propertyTitle').html(address.number+' '+address.street+' '+address.propertynumber+'<br>'+address.city+' '+address.state+' '+address.zip);
$(this).closest('.step').hide().next('.step').show();
return false;
});
$('.back').click(function(){
$(this).closest('.step').hide().prev('.step').show();
return false;
});