i have the follow code:
<input class="any" type="text" id="myId" name="myName" />
this input is a jquery datepicker.. (http://jqueryui.com/datepicker/)
My JS is as follows:
$('#myId').keypress(function(evt) {
//codes
});
I tried keypress, keydown and keyup.. all not working in IE..
May be because of the jquery date picker plugin?
I also tried with jquery hotkey plugin (https://github.com/jeresig/jquery.hotkeys/blob/master/jquery.hotkeys.js)
But, no success :(
i just want to capture the enter event..
Any help?
Felipe
If the element doesn't exist on the page on the initial load, then the event may not be bound to the button. Not sure why it works in other browsers though.
Could possibly try this to see if it helps
$(document).on('keypress', '#myId', function() {
// ....
});
if you're using an older version of jQuery, then you'll need to use .live().
Solved: http://jsfiddle.net/MJWUw/
IE doesn't recognize a keyevent just with click in this input, but if i navigate until the field with tabspace it works..
i did a workaround to solve this, set the focus manually and it's working right now.
$("#myId").click(function(evt){$(this).focus();});
$('#myId').keyup(function(evt) {
alert('working!')
});
att
Related
I've got follow code:
$(document).ready(function() {
let element = $('.inputField');
element.on({
'input': function(e) {
console.log('input');
},
'blur': function(e) {
console.log('blur');
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input class="inputField">
<input>
<button>Click here</button>
I use two events on my input. The first event is the input. I use this to detect if something was written in my input. The second one is the blur. With this event I detect if the focus on my input was lost (for example with tab into next input) or if the user clicked outside the input (for example on the button). Now this works fine on chrome. I also need it on internet explorer, but there the blur doesn't work. I looked at this questions:
jQuery blur event not firing
jQuery blur() or focusout() not firing in Internet Explorer
Blur event not working in IE11 and IE10
I could not find a solution to my problem. Any ideas? Thanks
Try to use ES5 syntax replace ES6.
I've been battling with this for for 2 years... need your help.
In mobile chrome, I cannot disable AUTOCOMPLETE ...
Chrome ignores
autocomplete="off"
This is on android, but I presume on iPhone also.
I have a simple contact form - no passwords or anything.
I absolutely need this to work, becasue on mobile, when chrome shows Autocomplete options, it breaksuser experience. How do I force Chrome mobile to not show it???
I've read like every question on this and nothing worked - I don't know what to do
Chrome keeps changing the way it handles autocomplete on each version, I solved this using jQuery, I make all the fields readonly and onclick/focus make it Not readonly. try this jQuery snippet:
jQuery(document).ready(function($){
//======fix for autocomplete
$('input, :input').attr('readonly',true);//readonly all inputs on page load, prevent autofilling on pageload
$('input, :input').on( 'click focus', function(){ //on input click
$('input, :input').attr('readonly',true);//make other fields readonly
$( this ).attr('readonly',false);//but make this field Not readonly
});
//======./fix for autocomplete
});
If you have a form, you could try with adding autocomplete="off" to form as well.
I have been searching for how to trigger the android keyboard via Javascript.
I have found a few answers but none of them seem to work.
One solution is here:
Showing Android's soft keyboard when a field is .focus()'d using javascript
On the example above there is a button involved which I don't have, but do I need it?
I am using 'tap' and 'swipe' events via the touch-layer.js which seems to disable click events in favour of tap. (https://github.com/cubiq/touch-layer)
Below is the code I've tried, the alert triggers and the focus happens but the keyboard doesn't show.
gt("#txtEmail").on("tap", function() {
alert('tap');
$(this)[0].el[0].focus();
$("#txtEmail").trigger('click');
});
Thanks.
EDIT 1: Second attempt doesn't work even though this seems more inline with the example.
gt("#txtEmail").on("tap", function() {
alert('trigger');
$("#txtEmail").trigger('click');
});
$("#txtEmail").on("click", function() {
alert('recieved');
$(this).focus();
});
In addition to Jack He's suggstion, check out ionic-plugin-keyboard. This one is more actively maintained and used by many.
In my case, I just bound focus event to a handler function that manually shows the keyboard.
$(".my-input").on("focus", function(e) {
...
cordova.plugins.Keyboard.show();
...
});
What you need is the SoftKeyBoard plugin. Just check the link to find what you want.
I'm really stuck with a jQuery issue and I hope someone can help me out...
So I have a list of options on the left, and when you click on one, a form is generated via Ajax on the right. There's this element in the form:
<input type="text" class="value" value="something">
And what I want to do is to call
$(".value").tagsInput();
which is a jQuery plugin that works pretty much like Stack Overflow's 'Tags' input field when you ask a question.
So I tried this:
$(document).ready(function() {
$(".value").on("load", function () {
console.log("Tags Input");
$(".value").tagsInput();
});
});
and nothing is printed out. I've also tried this:
$(document).on("change", ".value", function () {
console.log("Tags Input");
$(".value").tagsInput();
});
and it doesn't work either. I'm wondering where I did wrong. Can anyone help me out?
As pointed out by Shabnam, the "change" event is not what you want, as it is fired only once the field is blurred.
Anyways, from the plugin documentation, it looks like you don't have to call that function every time a key is pressed, but it attaches its own event handlers autonomously.
So, probably you should be fine with just:
$(document).ready(function() {
$(".value").tagsInput();
});
Your .on handler will never work, as the load event is fired only by document when the page is ready.
If you want to debug things a bit, have a look at the supported callbacks, such as onChange.
SIDE NOTE
I don't like how that plugin is written, as it clogs the "global" jQuery.fn namespace with lots of functions, while jQuery documentation recommends not doing so (see: Namespacing).
UPDATE
See here: http://jsfiddle.net/aFPHL/ an example of this working (the .load() was monkeypatched to avoid having to call an actual URL, but its behavior is pretty much the same as the real one).
"change" event gets fired when the input element loses focus. If you want ajax call at the end of each key input, try using keyboard events
I'd like to run a function upon each modification of a textbox control as soon as the user is typing. the event .keyup() is fine for most of the cases.
However, browsers (like Chrome or Firefox) may suggest autocompletion entries for textbox controls (probably because the #name or #id of the input control is known).
Unfortunately, I can't have any of the below events fired when "clicking on a suggested entry". ( .keyup() fires when selected with keyboard )
$('input#email')
.click(function() { console.log('click'); })
.keyup(function() { console.log('keyup'); })
.keydown(function() { console.log('keydown'); })
.change(function() { console.log('change'); })
.focus(function() { console.log('focus'); })
.blur(function() { console.log('blur'); });
As much as possible, I'd like to avoid using a setInterval() periodical check.
Is there a way to detect this "select a suggestion" event ?
bind propertychange event:
$('input').bind('input propertychange', function() {
var input = this.value.trim();
[...]
});
The short answer is no, there is no event for detecting a suggestion selection. You could try looking at DOM mutation observers but I'm uncertain if these cover attribute changes, and there is little support for this API so far anyway.
So if you really need to handle this case then I think setInterval is your only option.
Edit: 3 years later you can use propertychange with jQuery as in the new accepted answer (which I assume uses mutation observers under the hood).
alternative solution disable autocomplete and handle other events like keyup,keydown etc
<input type="text" name="foo" autocomplete="off" />
The change event seems to works fine, but does require you to click away