Catalina
Catalina

Reputation: 95

Ignore next line when enter is pressed

Is there are any solutions to ignore moving to the next line? For example, I have a textarea and when I click enter my form is being sent but at the same time a cursor is moved to the next line, that I don't want.

Edit: The problem is solved!/Проблема решена!

Upvotes: 0

Views: 106

Answers (2)

Shivani
Shivani

Reputation: 347

Use the attribute 'autocomplete' in input. See example below

Upvotes: 1

Rayon
Rayon

Reputation: 36599

If you do not want behavior of textarea, use input type='text' instead.

To prevent enter key ,

Attach keypress event and Event.preventDefault() if keyCode is 13(EnterKey)

$('#ta').on('keypress', function(e) {
  if (e.keyCode === 13) {
    e.preventDefault();
  }
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<textarea name="" id="ta" cols="30" rows="10"></textarea>

Fiddle Demo

Upvotes: 2

Related Questions