Saturday, April 27, 2019

javascript - How can I trigger onclick function when I press enter button?




I use the code below to update the url link based on user text input:










Right now it works pretty fine when someone clicks the submit button. What I want is to make it also work when a user press the enter button. Fiddle HERE


Answer



Try with this:



$(document).keypress(function(e) {
if(e.which == 13) {

var url = "/tag/";
url += $('#q').val();
window.location = url;
}
});

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...