How to prevent submit form on enter key except textarea in JQuery?

How to prevent submit form on enter key except textarea in JQuery?

In this post we will give you information about How to prevent submit form on enter key except textarea in JQuery?. Hear we will give you detail about How to prevent submit form on enter key except textarea in JQuery?And how to use it also give you demo for it if it is necessary.

In this post, i will show you how to prevent form submitting on enter key with except textarea using javascript code. You can simply do this on your php, laravel, codeigniter, asp.ent etc project.

In somecases, we require to disable form submit on press enter key on text box that way user must need to press submit button. We can do it simply but if we have to also textarea on that form that it can be cause issue because textarea should accept enter key and goes new line. However, we can also solve this issue by jquery code. So first let’s see bellow few lines code for prevent form submit on enter.

JQuery Code:

$(document).ready(function() {

$(window).keydown(function(event){

if((event.keyCode == 13) && ($(event.target)[0]!=$("textarea")[0])) {

event.preventDefault();

return false;

}

});

});

As above, you can see simply we can use in your jquery. I also added full example of this code. So if you don’t know how it should work then you can see bellow full example.

index.html

<!DOCTYPE html>

<html>

<head>

<title>JQuery prevent to enter to submit except Textarea</title>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>

</head>

<body>


<form method="POST">

<strong>Name:</strong>

<input type="text" name="name" placeholder="Name">


<strong>Details:</strong>

<textarea></textarea>


<button type="submit">Submit</button>

</form>


<script type="text/javascript">

$(document).ready(function() {

$(window).keydown(function(event){

if((event.keyCode == 13) && ($(event.target)[0]!=$("textarea")[0])) {

event.preventDefault();

return false;

}

});

});

</script>


</body>

</html>

I hope it can help you….

Hope this code and post will helped you for implement How to prevent submit form on enter key except textarea in JQuery?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

6  +  4  =  

We accept paid advance and paid guest Posting on our Site : Contact US