I need to trigger the ajax call when the Enter
key is pressed (keycode 13), but this is not triggering the button click correctly:
<div class="input-group col-md-6">
<input type="text" class="form-control" placeholder="Search by Asset ID" maxlength="64" class="form-control" id="imageid" name="imageid"> <span class="input-group-btn">
<button class="btn btn-default image-search" type="button">Search</button>
</span>
</div>
$('#imageid').keyup(function () {
this.value = this.value.replace(/[^0-9\.]/g, '');
if (event.keyCode == 13) {
alert(keyCode);
event.preventDefault();
$('.image-search').click();
}
});
$('.image-search').on('click', function () {
$.ajax({
url: url
method: 'GET',
});
}
JSfiddle: link
UPDATE:
I added the rest of the functionality, and now the keyCode
functionality no longer works. I tried creating one $(function () { //code });
, but this is making no difference. When removing lines 1-173, the functionality works. I think I'm just missing something simple here...
UPDATED Fiddle: link