0

I have a code that checks if both fields have the same value:

$ampD.blur(function() {
      setInterval(update, 1000);

      function update() {
        if ($('input#autocompletegoogle').attr('value') == $('input#field-address').attr('value')) {
          $ampD.attr('style', '');
        } else {
          $ampD.attr('style', 'border: 1px solid #f00!important;background: #ffefef !important');
        }

But sometimes $('input#autocompletegoogle') contains additionals marks example:

"5611JM Eindhoven, Netherlands"

but input#field-address contains "Eindhoven, Netherlands" and I get false.

How can I check in whether $('input#autocompletegoogle') contains value from $('input#field-address')?

I tried to find the solution almost one hour... I could find right information. Somone could help me?

Tyler Roper
  • 21,445
  • 6
  • 33
  • 56
kibus90
  • 315
  • 2
  • 11

1 Answers1

0

Simply modify your if condition to use something like includes() instead of ==.

var fieldAddress = $('input#field-address').val().toLowerCase();
var autoCompleteGoogle = $('input#autocompletegoogle').val().toLowerCase();

if (autoCompleteGoogle.includes(fieldAddress)) {
    //Auto Complete Google contains Field Address
}

If you'd prefer it remain case-sensitive, you can remove the toLowerCase() from each.

Tyler Roper
  • 21,445
  • 6
  • 33
  • 56