onkeypress

keypress event doesn't log input value first time event is fired

老子叫甜甜 提交于 2020-06-14 15:04:57
问题 The first time a keypress event fires, it logs an empty input value even though the input has a value. The second time it logs the value but is one keystroke behind in comparison with the input's value. You can check this behavior on the next example: document.addEventListener('DOMContentLoaded', () => { const input = document.querySelector('input'); input.addEventListener('keypress', e => { console.log(e.target.value); }); }); <input type="text"/> However, the next workaround makes it work,

keypress event doesn't log input value first time event is fired

北慕城南 提交于 2020-06-14 15:02:51
问题 The first time a keypress event fires, it logs an empty input value even though the input has a value. The second time it logs the value but is one keystroke behind in comparison with the input's value. You can check this behavior on the next example: document.addEventListener('DOMContentLoaded', () => { const input = document.querySelector('input'); input.addEventListener('keypress', e => { console.log(e.target.value); }); }); <input type="text"/> However, the next workaround makes it work,

Slideshow on key press not working properly

久未见 提交于 2020-02-23 04:36:25
问题 So I have this code. I'm doing something wrong. I want the left arrow to go back (show the previous image) but it isn't working. It shows the next image (like the right arrow). Whatever arrow I click, left or right it shows the next image. I've tried millions of different things and I can't seem to find the problem. Can anyone help me? I also like the sources to loop. When the last source from the array has been reached, I want to loop back to the first source again (and to the last source

jQuery .keyPress() - How to get value of input which triggered event?

只谈情不闲聊 提交于 2020-01-13 10:08:08
问题 Trying to do some jQuery validation (without the plugin - please no answers like "Just use the validate-js plugin"). I'm wiring up a client-side event handler keypress for each "required field" on doc ready: $(document).ready(function() { $('#myform input.required').each(function() { $(this).keypress(onRequiredFieldKeyPress); }); }); Which correctly fires this event on each keypress: function onRequiredFieldKeyPress() { if ($(this).val().trim() == '') { $(this).next('em').html('*').show(); //

How do I create KeyEvents in Java FXML?

狂风中的少年 提交于 2020-01-07 03:27:11
问题 I created this small project to test key events. But when I press keys, it isn't behaving as I want. Actually I need key events for my Calculator project. I created a Calculator project and aside from mouse clicks, I want to add a feature where numbers or operators can be typed from a keyboard. Can anyone check this and help make it more functional? public class FXMLDocumentController implements Initializable{ @FXML private Label label; @FXML private Button backSpace; @FXML private Button

How to cause button click event when enter is pressed in an hta application

北城以北 提交于 2020-01-06 08:24:12
问题 I have a script that allows me to hide a folder on my pc (using batch file). I've just implemented an hta application to it for the password so It's more seccure. Now the problem I'm having is that if I want to press enter to submit the form on the hta application, it just clears the password field and does nothing. I would like it to have the same effect as if I were to push the OK button. This is the hta part of my batch file: :HTA <html> <head> <title>Password Entry</title> <hta

Javascript problem with location.href

笑着哭i 提交于 2020-01-06 06:18:27
问题 I have a textbox and whenever the user presses a key it's checked to see if the user pressed enter. If the enter key is pressed, i want to add all the info in the textbox and transfer the user to a different url. <script language="javascript" type="text/javascript"> function checkEnter(e){ //e is event object passed from function invocation var characterCode; if(e && e.which){ //if which property of event object is supported (NN4) e = e; characterCode = e.which; //character code is contained

React Component passes Proxy object instead of Event object to the handler function

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-03 11:33:48
问题 I have prepared the following React Component (React version 1.5.2): var QuickSearch = React.createClass({ searchHandler: function(){ this.props.parent.props.dataSource.search = this.refs.SearchInput.value; this.props.parent.props.dataSource.setPage(1); this.props.parent.getData(); }, refreshHandler: function(){ this.props.parent.props.dataSource.search = this.refs.SearchInput.value; this.props.parent.getData(); }, myEventHandler: function(evt){ console.log(evt); if(evt.keyCode === 13) { evt

Detecting command + keystroke in Safari

空扰寡人 提交于 2020-01-02 06:31:28
问题 I'm trying to intercept the command + keystroke in Safari. I've added an event handler as follows: document.onkeypress = handleKeyPress; function handleKeyPress(event) { if ("+" === String.fromCharCode(event.charCode) && event.metaKey) { // my code here return false; } return true; } When I hit command shift = ( shift = is + on my US keyboard), the if statement does not return true. If I remove the event.metaKey portion of the if statement and hit shift = , the if statement does return true.