I have a PHP function that looks like this:
addPhone('859080', '111111111');
How can I call that function, from JavaScript, using AJAX, when I select a specific field on the form?
I have a PHP function that looks like this:
addPhone('859080', '111111111');
How can I call that function, from JavaScript, using AJAX, when I select a specific field on the form?
You can use ajax to make this work like this:
You HTML goes like this:
<button id="addPhone" data-phone="9999999999">
Add Phone 9999999999
</button>
You JS (jQuery) goes like this:
$('#addPhone').on('click', function(e) {
phone = $(this).data('phone');
addPhone(phone);
});
function addPhone(phone) {
$.ajax({
url: "url_to_php_function",
type: 'json',
data: {
'phone': phone
},
success: function(data){
// You can access response here in data variable
},
failure: function(data){
// handle errors here
}
});
}
Hope this Helps!