Confused about getting result from another function.
Clicking in button
I need the value of dgInput
- if Enter
on keyboard is pressed.
$('button').on('click', function() {
let str = fn();
console.log(str);
});
function fn() {
$('#dgInput').show().focus();
$('#dgInput').on('keypress', function(e) {
if (e.keyCode == 13) {
return ($('#dgInput').val());
}
});
}
#dgInput {
display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button>CLICK</button>
<br><br>
<input type='text' id='dgInput'>