If someone presses the Enter key I want to simulate as if he has pressed the space bar. I tried the below but it is not working. Pressing enter does nothing. Please help
$(document).ready(function() {
var spacepress = $.Event("keypress", {
keycode: 32,
which: 32
});
$('input').on("keypress", function(e) {
if (e.which == 13) {
e.preventDefault();
$('input').trigger(spacepress);
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type='text'>