function submitDeviceNumber(){ var ean = $('#txtean1').val(); var deviceID=ean.replace('-','_'); var jqxhr = $.getJSON( "/../articles/getDeviceByNumber/"+deviceID.replace('/','_'), function(data) { //console.log( data ); if (data.device===null) { console.log("Nincs ilyen: "+ean) $('#txtean1').val("Nem Található!"); $('#txtean1').select(); } if (data.device && data.work) { $('#exampleModal').modal('toggle'); window.location.replace("/components/new/"+data.device._id+"/"+data.work._id); } //console.log("/components/new/"+data.device._id+"/"+data.work._id); }) } $('#exampleModal').on('shown.bs.modal', function () { $('#txtean1').focus(); }) // Get the input field var input = document.getElementById("txtean1"); // Execute a function when the user releases a key on the keyboard input.addEventListener("keyup", function(event) { // Cancel the default action, if needed event.preventDefault(); // Number 13 is the "Enter" key on the keyboard if (event.keyCode === 13) { // Trigger the button element with a click //document.getElementById("myBtn").click(); submitDeviceNumber(); } });