Define Variable:
// Define Autocomplete Location Variable
var ac_location;
Set variable:
// Set Autocomplete Location Variable Equal to input id "loc"
$("#loc").val(ac_location);
Print variable:
// Print Autocomplete Variable
alert(ac_location);
Compare variable:
// Compare "#loc" input with ac_location variable
if (ac_location.val() != $("#loc")) {
// Print Autocomplete Variable
alert(ac_location);
} else {
alert("No match");
}
I have tried to use information from jquery help and google to do this. This is the complete code:
What is wrong with my steps, because console says my val is undefined and it doesnt print out the varialbe in the alert box. Any help would be very much appreciated.
simply you set value of element
#loctoac_location, not vice versa. Doand write
ifproperly, your jquery object is#locnotac_locationand what’s more, after comparison you
alert("No match");when yourifstatement matches.