Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I try to handle the key press event in javascript, after user press a key on keyboard, it will print the pressed key on screen. I know I need to handle the onkeydown event, but how to do that in detail?
You can use jQuery to do this job, using jQuery will make your program run well in different browsers.
$(function(){
$(document).keypress(function(event){
console.log(event.which);
});
})
Above code uses keypress function to handle key press event, and print the pressed key's key code to your browser console
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 12 months ago.
Improve this question
I want to achieve following algorithm:
Preconditions:
You are logged in instagram web version
You see the default home page
You are using chrome
It should be done via console tab in chrome
Task:
Do in vanilla JS the focus of the input field with a recommendation window
i.e
Focus the field, input cats, submit it and see the recommendation window
let search = document.querySelectorAll('[placeholder="Поиск"]')[0];
search.focus();
search.click();
Expected behaviour:
Search input found
Search input focused
Recommendation popup appeared
Actual behaviour:
Search input found
Search input not focused
Thank you for any assistance!
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a lot JS files in legacy project. Some JS code is blocking form submit, how I can find what JS events is listening form submit ?
Chrome actually has a great tool that is able to do this. Right-click on the submit button and open dev tools. Then go to event listeners in the sub tab from there you should be able to see the submit action. You can expand the action and view the source.
the comments are a good start, additionally search through all files for any reference to the forms name or id and if thats not enout for any code looping through all forms.
depending on the techniques used, e.g. jquery you might need to change your search like
document.getElementsByTagName("form")
$("form")
$("#ID_OF_FORM).submit
and so on... i guess best chances by using the ID of the form
You can also add event listener in Console Tab.
More in article below.
How to debug Front-end: Console
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I need to get the current active element on my web page I used
$(document.activeElement)[0].id
This is working fine in Internet Explorer, but in Firefox it always return empty string ""
Please tell me how can I get active element's id in Firefox?
Here is a simple scenario
I have 2 div with ID div1 and div2 respectively, now when user click on them I should get it's ID
Here is my markup
http://pastebin.com/BCW8ECMx
Why not use the event's target:
$(document).ready(function () {
$(document).click(function (e) {
alert(e.target.id);
});
});
JSFiddle example found here.
The problem is not in the code. But, the fact that, div cannot be active.
In fact, elements, which a user cannot interact, cannot be active.
For such elements, the id of the <body> will be returned.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I am doing an add client form(in modal view) I want to place an error message in the modal header.
Yes, I am able to do that. The problem is, the modal will close and the message will be showed after
the user open it again.
How to make the modal stay open with the error displayed. Thank you. Newbie here.
You detect the click event on the button when fired, then make your test, if the stuff is good, you let submit (don't cancel the event ) otherwise, you cancel the event and show the error. Here is an example:
$(document).ready(function() {
$( "#button" ).click(function( event ) {
if (error){
show error
event.preventDefault();
return false;
}
});
});
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to get forwarded to a page called 'test.html' by typing in the sentence 'hello' on the page. For example, when I type in 'hello' on the page, I would get forwarded to test.html . It wouldn't be in a text box; I would type it without seeing what I'm typing. I've researched this online but can't find anything on this topic.
I don't know what purpose it will serve but You can do something like that.
Add keypress listener on document.
Maintain one variable for holding the typed text say sec.
in your key press listener,
Concatenate the pressed key with the sec and compare if
sec=="hello" do redirect
DEMO
Javascript
(function(){
document.addEventListener("keypress",fun);
var sec='';
function fun(e){
sec += String.fromCharCode(e.keyCode);
if(sec=="hello"){
alert("Hello typed!"); //replace this with redirect
sec='';
}
}
})();