Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have an chat application with php !
and when u write your message in texteria and click on Enter it send message ....
its with mvc and ajax an ... ! I cant find with Function Run when u click on Enter !
Can I set a Button near that and Run the textbox keypress function in onclick ?
somthing like this ?? :
<button ></button>
Posted

Hi,

You need to check for keycode 13 which stands for Enter key.
HTML
<html>
	<head>
 	<script>
	function process(e)
		{
			var code = (e.keyCode ? e.keyCode : e.which);
			if(code == 13) { //Enter keycode
				alert("Sending your Message : " + document.getElementById('txt').value);
			}
		}
     </script>
 </head>
	<body>
	<textarea id="txt" cols="40" rows="5" onkeypress="process(event, this)">
	</textarea>
	</body>
</html>


Thx
 
Share this answer
 
Comments
+5. I created the demo on your example. See Solution 2.
‫محم د‬‎ 3-Dec-14 1:23am    
i found ew.wich == 13 ! but i cant find my textbox id in .js file !
<textarea id="dialogTextarea" class="invitation"></textarea>
Just to support what srikantsahu said, a simple Demo...

[Demo] Detect Enter Key Press on TextArea[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900