'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 1:[1]
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>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Omar Tammam |
