Submit form on Enter key with javascript
Try this: document.getElementById(’email’).onkeydown = function(e){ if(e.keyCode == 13){ // submit } };
Try this: document.getElementById(’email’).onkeydown = function(e){ if(e.keyCode == 13){ // submit } };
Give this a shot… private void input_KeyDown(object sender, KeyEventArgs e) { if(e.KeyData == Keys.Enter) { MessageBox.Show(“Pressed enter.”); } }
var code = (e.keyCode ? e.keyCode : e.which); if(code == 13) { //Enter keycode alert(‘enter press’); }
Try this: $(‘#myText’).on(“keypress”, function(e) { if (e.keyCode == 13) { alert(“Enter pressed”); return false; // prevent the button click from happening } }); Demo
try this $(“textarea”).keydown(function(e){ // Enter was pressed without shift key if (e.keyCode == 13 && !e.shiftKey) { // prevent default behavior e.preventDefault(); } }); update your fiddle to $(“.Post_Description_Text”).keydown(function(e){ if (e.keyCode == 13 && !e.shiftKey) { // prevent default behavior e.preventDefault(); //alert(“ok”); return false; } });
This is not specific to JSF. This is specific to HTML. The HTML5 forms specification section 4.10.22.2 basically specifies that the first occuring <input type=”submit”> element in the “tree order” in same <form> as the current input element in the HTML DOM tree will be invoked on enter press. There are basically two workarounds: Use … Read more
Try: String str = “my string \n my other string”; When printed you will get: my string my other string
Using <button type=”button”>Whatever</button> should do the trick. The reason is because a button inside a form has its type implicitly set to submit. As zzzzBoz says, the Spec says that the first button or input with type=”submit” is what is triggered in this situation. If you specifically set type=”button”, then it’s removed from consideration by … Read more
import org.openqa.selenium.Keys WebElement.sendKeys(Keys.RETURN); The import statement is for Java. For other languages, it is maybe different. For example, in Python it is from selenium.webdriver.common.keys import Keys
Angular supports this out of the box. Have you tried ngSubmit on your form element? <form ng-submit=”myFunc()” ng-controller=”mycontroller”> <input type=”text” ng-model=”name” /> <br /> <input type=”text” ng-model=”email” /> </form> EDIT: Per the comment regarding the submit button, see Submitting a form by pressing enter without a submit button which gives the solution of: <input type=”submit” … Read more