I have an object, data, that may or may not contain the members site_with_same_coords and/or site_with_same_name. I test for these and if one or both exist, I alerts to the user:
if (data.site_with_same_coords){
var SameCoordsExists = true;
same_coords_message = 'The site ';
same_coords_message += data.site_with_same_coords.name;
same_coords_message += 'already already exists in the location you have indicated';
}
if (data.site_with_same_name){
var SameNameExists = true;
same_name_message = 'The site ';
same_name_message += data.site_with_same_name.name;
same_name_message += 'already already exists in a differnt location from the one you have indicated';
}
if (SameCoordsExists && SameNameExists){
if(data.site_with_same_name.id != data.site_with_same_coords.id){
alert(same_coords_message + '\n' + same_name_message);
}else if (SameCoordsExists){
alert(same_coords_message);
}
}else if (SameNameExists){
alert(same_name_message);
}
}
Is there a better way of doing this?
Sure, you could put them in an array and join them:
Also, wouldn’t the user be a bit confused if they received the message:
? Just a thought.