How to press enter key automatically using Jquery
Try keyup
event instead of change
event
$("#table1_filter input").val(this.value).trigger('keyup')
Jquery: how to trigger click event on pressing enter key
try out this....
$('#txtSearchProdAssign').keypress(function (e) {
var key = e.which;
if(key == 13) // the enter key code
{
$('input[name = butAssignProd]').click();
return false;
}
});
$(function() {
$('input[name="butAssignProd"]').click(function() {
alert('Hello...!');
});
//press enter on text area..
$('#txtSearchProdAssign').keypress(function(e) {
var key = e.which;
if (key == 13) // the enter key code
{
$('input[name = butAssignProd]').click();
return false;
}
});
});
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<textarea id="txtSearchProdAssign"></textarea>
<input type="text" name="butAssignProd" placeholder="click here">
</body>
</html>
Press the enter key in a text box with jQuery
Use keypress
then check the keycode
Try this
$('input').on('keypress', function(e) {
var code = e.keyCode || e.which;
if(code==13){
// Enter pressed... do anything here...
}
});
OR
e = jQuery.Event("keypress")
e.which = 13 //choose the one you want
$("#test").keypress(function(){
alert('keypress triggered')
}).trigger(e)
DEMO
Can't auto submit when press enter key
Your HTML code is not proper.
The issue is with <
and >
characters.
e.g. here,
<form action='<?php echo site_url(); ?>account_c/login' method="POST">
You have to escape them for the form to generate the URLs properly.
Check if the action url is created properly on page, I bet it won't be.
Your form is actually getting submitted but not going anywhere.
Try with,
<form action='<?php echo site_url(); ?>account_c/login' method="POST">
Similarly,
<a href="<?php echo site_url(); ?>/home/forgotpasswordmail""
should be,
<a href="<?php echo site_url(); ?>/home/forgotpasswordmail">
How can I automatically trigger an enter key press event after a certain action is executed?
Create a variable that tells us if the user has clicked your button.
var clicked = false;
Add an event listener to your button, so that when the user clicks on it, the
clicked
variable will becometrue
.myButton.addEventListener('click', function(){
clicked = true;
});Add a
keypress
event listener:document.addEventListener('keypress', function(e) {
// `e` is the event
});Inside that event listener, check if the user clicked previously
if(clicked) {
// ...
}If (s)he did, check the pressed key. Enter's key code is 13.
var keynum = e.keyCode||e.which;
if(keynum == 13) {
// ...
}If the pressed key was enter, use
clicked = false;
Otherwise, once the user clicked your button and pressed enter, it wouldn't be necessary to click the button again.
After that run your code. For example, this will call function
f
after 2 seconds.setTimeout(f, 2000);
Live demo
var clicked = false;document.querySelector('#btn').addEventListener('click', function(){ clicked = true; snippet.log("You clicked the button. `clicked` is now `true`");});document.addEventListener('keypress', function(e) { if(clicked) { var keynum = e.keyCode || e.which; if(keynum == 13) { clicked = false; snippet.log("`clicked` is now `false`. Waiting 2 seconds..."); setTimeout(f, 2000); } }});function f() { snippet.log("Function `f` executed successfully!");}
#btn { border: 3px solid red; cursor: pointer;}
<div id="btn">Click me, and then press enter.</div><!-- Provides the `snippet` object, see http://meta.stackexchange.com/a/242144/134069 --><script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script>
Related Topics
React Native How to Call Multiple Functions When Onpress Is Clicked
How to Show an Alert After Reloading the Page in JavaScript
Executing Nodejs Script File in PHP Using Exec()
Detect If String Contains Any Spaces
How to Use Owl Carousel Vertically
Onclick Table Row With Onclick Button and Bootstrap Modal Inside
Generate Child Row Under a Parent Row in HTML Table
Textarea With Initial Auto Height by Content With Pure CSS
Howto Trigger Input Event Programmatically on Input Text Field
Javascript Validation: Block Special Characters
How to Create a Remember Me Function in Login Without Using Form in JavaScript or Jquery
How to Stop Parsefloat() from Stripping Zeroes to Right of Decimal
How to Prevent the Keyboard from Popping Up on Mobile Devices
Charts.Js Graph Not Scaling to Canvas Size
Have a Div Move on Scroll Up and Down
Merge Array of Objects by Same Key-Value
Update Value in Localstorage Array by Existing Key
Create React App Breaks After Deployment on Refresh 404 With Nginx