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 >
<input type="text" id="type" value="">
<input type="text" id="model" value="">
</div>
<script>
$("#type").on('keydown', function() {
var key = event.keyCode || event.charCode;
if( key == 8 || key == 46 )
$("#model").empty();
});
</script>
CodePudding user response:
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>