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?

2
  • Possible duplicate of JQuery string contains check Commented Aug 12, 2018 at 3:27
  • Can you provide a working example with the data you're trying to process? Commented Aug 12, 2018 at 3:29

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.