Asked 30+ days ago
10 Oct 2017
Views 365
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 Dec 12 '17 20:17

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
Edit Answer
Share
Post Answer