When I press search button my JS code will work.
But when I use enter to submit form Bellow code will not work.
Use of code in magento.
Html
<form action="<?php echo $this->getUrl('storelocator/index/searchbydistance') ?>" method="GET" id="search_by_distance">
<button type="button" onclick="storeSearch.submit(this)"><?php echo $this->__('Search') ?></button></form>
Javascript
<script type="text/javascript">
//<![CDATA[
storeSearch.submit = function(button, url) {
alert('hi');
}.bind(storeSearch);
//]]>
2
Answers
For the enter keypress form submission behaviour to work you need to have
submit
button within the<form>
element. As all your current button does is submit the form through JS, you could simply change itstype
:give some id to to button and then use code like following:
//OR submit your form.