Textarea enter submit

<html lang="eng">
	<head>
		<title> Index Page </title>
		<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
		<script type"text/javascript">
		$(function(){
		$('#txtMessage').focus();
		
		$('#txtMessage').keydown(function(event){
		
		if(event.keyCode==13 && event.shiftKey) return;
		
		if(event.keyCode==13){
		var messageBody=$('#txtMessage').val();
		$('<p/>').html(messageBody).appendTo($('#content'));
		$('#txtMessage').val('').focus();
		event.preventDefault();
		}
		
		});
		
		});
		</script>
	</head>
	<body>

	<hr/>
	<hr/>
	
	<textarea id="txtMessage" col="50" rows="5" placeholder="Enter your message"></textarea>
	
	<div id="content" style="white-space:pre"></div>

	</body>
</html>

This script shows textarea enter submit , shift+enter is new line key also after submit shows place holder message again.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s