So the code that I have so far is:
<fieldset id="LinkList">
<input type="text" id="addLinks" name="addLinks" value="http://">
<input type="button" id="linkadd" name="linkadd" value="add">
</fieldset>
It is not in a <form>
and is just as it is within a <div>
. However when I type something into the textbox
called "addLinks" I want the user to be able to press Enter and trigger the "linkadd" button
which will then run a JavaScript function.
How can I do this?
Thanks
Edit: I did find this code, but it doesnt seem to work.
$("#addLinks").keyup(function(event){
if(event.keyCode == 13){
$("#linkadd").click();
}
});
button
with asubmit
submit
handler of the form, not theclick
handler of the buttonPressing enter in the field will trigger form submission, and the submit handler will fire.
I am using a kendo button. This worked for me.
It is 2019.
DO NOT USE
keypress
keypress
event is not triggered when the user presses a key that does not produce any character, such as Tab, Caps Lock, Delete, Backspace, Escape, left & right Shift, function keys(F1 - F12).It has been deprecated.
DO NOT USE
KeyboardEvent.keyCode
What should I use then? (The good practice)
It works when input type="button" is replaced with input type="submit" for the default button which needs to be triggered.
This should do it, I am using jQuery you can write plain javascript.
Replace
sendMessage()
with your functionality.