Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Compare 2 fields <input>, clear the second one

If the first and second fields have the same text despite the font and spaces, then delete the second one text

$(document).ready(function() {
  var input_1 = $(".test_1");
  var input_2 = $(".test_2");
  $(input_2).focusout(function() {
    if (input_1.val() === input_2.val()) {
      $('.test_2').val('');
    }
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<input value="dom" class="test_1">
<input value=" Dom" class="test_2">

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Perhaps you want a trim and a lowerCase?

$(function() {
  const $input_1 = $(".test_1");
  const $input_2 = $(".test_2")
  .on("blur",function() {
    const val1 = $input_1.val().trim().toLowerCase(), 
          val2 = $input_2.val().trim().toLowerCase();
    console.log(val1,val2,val1 === val2);
    if (val1 === val2) {
      $input_2.val('');
    }
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<input value="dom" class="test_1">
<input value=" Dom" class="test_2">
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading