I have an input group in bootstrap which is an icon, a field and a button - for the purposes of user interface experience I would like the return key to call the function attached to the search button but only if that field is in focus.
Is this possible with native bootstrap or will some form of jQuery be needed? I wouldn't want the return keypress to be permanently used to activate this function, only if the user is using this input search field.
Thanks in advance
<div class="form-group">
<label class="control-label" for="another-location">Search for another location</label>
<div class="input-group">
<div class="input-group-addon" data-toggle="tooltip" data-placement="right" title="Location"><span class="fa fa-map-marker fa-fw"></span></div>
<input type="text" class="form-control gllpSearchField" id="another-location" placeholder="A location" name="another-location" />
<span class="input-group-btn">
<button class="btn btn-default" type="button">Search</button>
</span>
</div>
</div>
Yes you need Jquery :
$('#another-location').keypress(function(event){
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){
alert('You pressed a "enter" key in textbox, here submit your form');
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With