clock  Mon - Sun 8.00 AM - 8.00 PM
mail  edu@teknowize.com
fb
instagram
play store
pinterest

How To Prevent User Hitting Enter Except Textarea Using jQuery

  Sumit Dey Sarkar
  11 Sep 2022
  JQuery
Imperial Advance Hero Image

How To Prevent User Hitting Enter Except Textarea Using jQuery

In this article we will learn how to prevent user hitting enter except textarea using jQuery.

Let's see example -

How To Prevent User Hitting Enter Except Textarea Using jQuery

<!DOCTYPE html>
<html>

<head>
    <title>How To Prevent User Hitting Enter Except Textarea</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
</head>

<body>

    <h3>How To Prevent User Hitting Enter Except Textarea</h3>
    <form method="POST">
        <strong>Full Name:</strong>
        <input type="text" name="fullName" placeholder="Name">


        <strong>About Your Self:</strong>
        <textarea></textarea>


        <button type="submit">Submit Now</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>

 

Output

jQuery