Asked 7 years ago
10 Oct 2017
Views 2115
Cimb

Cimb posted

on enter keypress , form should be submit in JavaScript

form is submitting on Enter keypress but i want it submit by JavaScript.

	    <form method="get" action="">
              <input type="text" id="keyword" name="keyword" class="form-control" placeholder="Search here">
            </form>

so when enter keypress Javascript function should be call
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

event.keyCode is equal to 13 means user pressed enter button

 <form method="get" action="">
              <input type="text" id="keyword" onkeydown="if (event.keyCode==13) {onenter(this);}"   name="keyword" class="form-control" placeholder="Search here">
 </form>
<script type="text/javascript">
function onenter(d){
var site_url = 'http://example.com';
var d=jQuery(d).val();
window.location=site_url+'search/'+d;

}
</script>


and we are manually redirecting site with search keyword it is same as form submit
Post Answer