jquery - How can i pass javascript addListener function value to change function inside -
i have addlistener
function , change
function there. how can pass addlistener
result change
function inside using javascript
$(document).ready(function() { // find pincode var input = document.getelementbyid('location_input'); var options = { types: ['address'], componentrestrictions: { country: 'in' } }; autocomplete = new google.maps.places.autocomplete(input, options); var pincode; google.maps.event.addlistener(autocomplete, 'place_changed', function fun1() { var place = autocomplete.getplace(); (var = 0; < place.address_components.length; i++) { (var j = 0; j < place.address_components[i].types.length; j++) { if (place.address_components[i].types[j] === "postal_code") { pincode = place.address_components[i].long_name; fun2(pincode); //alert(pincode); } //return pincode; } } }); $('input[type="checkbox"],#location_input').change(function fun2(val) { var ids = ['filter_affiliation_1', 'filter_affiliation_2', 'filter_affiliation_3', 'filter_affiliation_4']; var data = {}; (var = 0; < ids.length; i++) { if (document.getelementbyid(ids[i]).checked === true) { data['request' + i] = $('#' + ids[i]).val(); } } var pincode = val; alert(pincode); console.log(pincode); }); });
here fun1
, fun2
2 functions. how can pass fun1
pincode
value fun2
inside?
you have defined pincode in global scope. use it. here function fun2(val)
val event
object passed event callback. , dont have use named functions, anon funcs work event callbacks.
$(document).ready(function () { // find pincode var input = document.getelementbyid('location_input'); var options = { types: ['address'], componentrestrictions: { country: 'in' } }; autocomplete = new google.maps.places.autocomplete(input, options); var pincode; google.maps.event.addlistener(autocomplete, 'place_changed', function () { var place = autocomplete.getplace(); (var = 0; < place.address_components.length; i++) { (var j = 0; j < place.address_components[i].types.length; j++) { if (place.address_components[i].types[j] === "postal_code") { pincode = place.address_components[i].long_name; } //return pincode; } } }); $('input[type="checkbox"]').change(function (event) { var ids = ['filter_affiliation_1', 'filter_affiliation_2', 'filter_affiliation_3', 'filter_affiliation_4']; var data = {}; (var = 0; < ids.length; i++) { if (document.getelementbyid(ids[i]).checked === true) { data['request' + i] = $('#' + ids[i]).val(); } } alert(pincode); console.log(pincode); }); });
wiki
Comments
Post a Comment