Possible Duplicate:
Javascript capture key
I'm working on reply function using mysql and php.
My MySQL db:
reply: rid - id; topicid - under which topic; uid - id of the guy who replies; content - what did the guy said.
Here's my html code:
<form id="replyform"> <textarea name="rplcont" placeholder="Press enter to submit your reply."><textarea> </form>
My question is: How do I know if enter button is pressed?
Many thanks.
/----------------------------------------------/
here's my codes that work:
html:
<textarea id="reply" name="reply" onKeyPress="enterpressalert(event, this)"></textarea>
js:
function enterpressalert(e, textarea){ var code = (e.keyCode ? e.keyCode : e.which); if(code == 13) { //Enter keycode alert('enter press'); } }
and it works.
Thanks for everyone who concerns this topic!
Using JavaScript In plain JavaScript, you can use the EventTarget. addEventListener() method to listen for keyup event. When it occurs, check the keyCode 's value to see if an Enter key is pressed.
To check whether user pressed ENTER key on webpage or on any input element, you can bind keypress or keydown event to that element or document object itself. Then in bind() function check the keycode of pressed key whether it's value is 13 is not.
To trigger a click button on ENTER key, We can use any of the keyup(), keydown() and keypress() events of jQuery. keyup(): This event occurs when a keyboard key is released. The method either triggers the keyup event, or to run a function when a keyup event occurs.
var code = (e.keyCode ? e.keyCode : e.which); if(code == 13) { //Enter keycode alert('enter press'); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With