I have the class of .addy applied to multiple inputs. I don't want to write a bunch of functions with the same code, so I would like to have if statements inside that tell function which parts to execute. This depends on where the action originates from: input#address1 or input#address2.
I need help with my if statement, please. How can I tell the function whether the #address1 or #address2 was where request originated?
$("input.addy").on('change', function(e) {
e.preventDefault();
var uid = $('form#data input[name=user_id]').val();
var bid = $('form#data input[name=business_id]').val();
if () { // If the change was made to input#address1, do the below
var address1 = this.value;
var data = {user_id: uid, business_id: bid, address1: address1};
$.ajax({
url: '/business/assignment/saveaddressone',
type: 'POST',
dataType: 'JSON',
data: data,
success: update
})
}
if () { // If the change was made to input#address2, do the below
// Here is address2 code
}
});
$(this).attr ("id") == "address1"