Hi all,
I am New in Javascript and Not Having too Much Knowledge of Javascript. I Have a Javascript That Disable Enter Key in Textarea in Whole Form in Page. but I Want to Disable Enter Key only One Textarea.

Below is my Code:

<html>
<head>
<title>The Title Of Your Page Goes Here!</title>
</head>
<body>
<script language="javascript" type="text/javascript">
function checkCR(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}
document.onkeypress = checkCR;
</script>

<p><center><form action="" method="post">
Enter Your Number<br><textarea cols="40" rows="5" name="field1" wrap="physical"></textarea><br>
Enter Your Message<br/><textarea cols="40" rows="5" name="field2" wrap="physical"></textarea>
<input type="submit" value="Send it!"><input type="reset" value="Clear it!" />
</form></center></p>

</body>
</html>

The Above Code Work Fine but This Disable The Enter Key in Twice Textarea but I Want to Disable Enter Key Only in First Textarea That is "field1".

Please Help Me.
Thank You.

I have checked your code.

Actually it does not disable enter key in TextArea. It disable enter key only in Textbox field. But you didn't use any textboxes in your code.


I have changed your code to disable enter key in first text area(field1) only.

<html>
<head>
    <title>The Title Of Your Page Goes Here!</title>
</head>
<body>

    <script language="javascript" type="text/javascript">

        function checkCR(evt) {

            var evt = (evt) ? evt : ((event) ? event : null);
            var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
            if ((evt.keyCode == 13) && (node.type == "textarea") && (node.name == "field1"))
 {
                return false;
            }
        }
        document.onkeypress = checkCR;
    </script>

    <p>
        <center>
            <form action="" method="post">
            Enter Your Number<br>
            <textarea cols="40" rows="5" name="field1" wrap="physical"></textarea><br>
            Enter Your Message<br />
            <textarea cols="40" rows="5" name="field2" wrap="physical"></textarea>
            <input type="submit" value="Send it!">
            <input type="reset" value="Clear it!" />
            </form>
        </center>
    </p>
</body>
</html>

Thanx Dear for Solving my Problem.
My Problem is Now Solved..
and am Mark this Thread to Solved..

Thanx once again duse.

another script you can try if need more advanced features :D; it then advances the cursor to the next field within the form. Very useful.

<script type="text/javascript">
/***********************************************
* Disable "Enter" key in Form script- By Nurul Fadilah(nurul@REMOVETHISvolmedia.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
	}      

</script>
	<!--
    	This script downloaded from www.JavaScriptBank.com
    	Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
	-->

Demo: JavaScript Disable 'Enter' Key in Form

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.