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

How to empty input when change another input

I want to empty the input value when another input value has changed.
I tried this code, but not working yet. Any idea to solve this issue?
Thanks in advance.

<div class="continer">
  <input type="text" class="type" id="type" value="">
  <input type="text" class="model" id="model" value="">
</div>

<script>
  $("#type").on('keydown', function() {
    var key = event.keyCode || event.charCode;
     if( key == 8 || key == 46 )
    $("#model").empty();
  });
</script>

>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

you can use change event to trigger the change event and .val() method to set the value of the other inputs , like that

<script>
  $("#type").on('change', function() {
    $("#model").val("");
  });
</script>
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