Al Bassam
Al Bassam

Reputation: 9

Pressing Enter Key in input type text isn't working

I have this HTML code

<form method="post" action="adminstudent.php" enctype="form-data/multipart">    
    <input type="text" id="searchStudent" class="form-control" name="txtsearch" placeholder="Search Student...">
    <input type="submit" name="btnsearch" value="Search" class="btn btn-warning">
</form>

and JQUERY to trigger if ENTER KEY is pressed

$('#searchStudent').keypress(function(event){
    if (event.keyCode == 13) {
        $('#btnsearch').click();
    }
});

But it just refresh when I pressed Enter Key.

Upvotes: 0

Views: 1029

Answers (1)

D4V1D
D4V1D

Reputation: 5849

Why would you want to develop a feature that is already implemented in all browsers since ages?

Just drop the jQuery altogether and leave the form as such. As long as you have have a <form> tag enclosing an <input type="submit" value="Send"/> (or <button type="submit">Send</button>), pressing the Enter key in any of the inputs will submit the form.

Upvotes: 1

Related Questions