I would like to submit a HTML form when the search field is active and the enter button is hit. The line below (this.$el.find('.icon-search').get(0).click();) works fine in every browser. In safari though I get an error.
init: function() {
if(!this.$el.hasClass('block-wheretobuy-map')){
this.setEventHandlers();
}
},
setEventHandlers: function() {
_.bindAll(this, "onFormSubmit", "_on_keydown");
this.$el.find('.icon-search').click( this.onIconClick );
this.$el.find('#frm_city').keydown( this._on_keydown );
},
_on_keydown: function(event){
if(event.keyCode == 13){
this.$el.find('.icon-search').get(0).click();
}
},
onIconClick: function ( event ){
var url = $(this).attr('href');
if (url.indexOf("?") >= 0) {
url = url + '&l=';
} else {
url = url + '?l=';
}
url = url + $('#frm_city').val();
$(this).attr('href', url);
},
HTML
<div class="block block-border block-wheretobuy ">
<div class="block-background"></div>
<h1 class="primary">Where to buy </h1>
<p>Find a store near you</p>
<div class="fieldset search">
<div class="placeholder" rel="commain_1comblockcontainertwocolumns_0$frm_city"><span>City, Postcode</span></div><input name="commain_1comblockcontainertwocolumns_0$frm_city" type="text" id="frm_city" class="field field-search" placeholder="" autocomplete="off">
<a href="/en/where-to-buy" class="icon-search tst-search"></a>
</div>
</div>
Error in Safari:
Safari TypeError: 'undefined' is not a function (evaluating 'this.$el.find(“.icon-search”).get(0).click()')