How can I set automatically clear my html input after click enter? It's complicated because my program uses ajax and php also. I tried to do this by jQuery $("#txt").val('') but then my input is clearing every single typed letter (I need to clear input only after click enter).
<html>
<body>
<div><label for="txt">Text:
<input id="txt" name="txt" type="text" value="" size="20"></label></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js">
</script>
<script>
$(window).load(function() {
$("#txt").keyup(function(event) {
if (event.keyCode == 13)
$.ajax({
url: 'hello.php',
data: {
func: 'test',
txtVal: $("#txt").val()
},
type: 'post',
});
$("#txt").val('')
});
});
</script>