0

I want to disable enter key in textarea on jsp but the function is not working and enter key still make new line when I press it.

Below is the function to disable enter key in textarea :

$("textarea").on("keypress", function(e) {
if ((e.keyCode == 13)) {
e.preventDefault();

    }
});

And there is the jsp :

<td><form:textarea path="connote.shipperAddr" id="shipperAddr" name="shipperAddr" onfocus="this.select();" onmouseup="return false;" onblur="whenEmpty(this);"
htmlEscape="true" 
rows="3" cols="34"
tabindex="5"/> <form:errors
path="connote.shipperAddr" cssClass="error" /></td>

How can I disable enter key from a textarea?

Tanmay
  • 590
  • 8
  • 20
kumala nindya
  • 69
  • 1
  • 1
  • 10

1 Answers1

0

Your code is working fine. Demo

$("textarea").on("keypress", function(e) {
if ((e.keyCode == 13)) {
e.preventDefault();

    }
});

Please make sure your selector $(textarea) is able to get the textarea element.Is form:textarea rendered as normal <textarea></textarea>.

Raghu
  • 909
  • 7
  • 23