0

I'm currently putting together a store locator using Google's new Store Locator Library for Maps API (http://storelocator.googlecode.com/git/index.html).

I want to add a 'search' button next to the search input field so people have the option of either hitting return or hitting the button to start the search.

I've tried editing the store-locator.compiled.js file but keep breaking the code?

  • What is the programming problem you need help resolving? – Sean Mickey Jun 07 '12 at 03:17
  • Hey Sean, In this example [link](http://storelocator.googlecode.com/git/examples/panel.html) there is no 'search' button next to the input field. Would like to add one but not sure how to go about it. The javascript outputting the html is compiled which makes it hard for me to work with - [javascript link](http://storelocator.googlecode.com/git/js/store-locator.compiled.js) – user1441095 Jun 07 '12 at 04:33

1 Answers1

1

I tried using Chrome's Dev Tools to go through your code but seems as though it's been minified so I didn't bother trouble shooting. Instead I'd suggest a work around, that may solve your issue.

Consider using jquery's trigger event to trigger a "keydown" (see top answer in Definitive way to trigger keypress events with jQuery). Now I've tweaked the code around a little to perform the action that you desire.

In the HTML mark-up you'll have your input field as well as the button:

<input type="text" name="blah" />
<button id="clickme" type="button">Click Me</button>

And in the Javscript, add a click event for the button with a function that triggers the keydown press for the "return key" - like so:

$("#clickme").click(function(){
    var e = jQuery.Event("keydown");
    e.which = 13; // # Some key code value
    $("input").focus(); //to ensure that the input field is in focus
    $("input").trigger(e);
});

That should do it, the button should replicate the keydown press of the return key on your input field - so you don't have to worry about tinkering with any of your current functionality in your code.

By the way, used this link to get the character code for "return key" - it has a whole list of codes for other characters http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes

Community
  • 1
  • 1
Suvi Vignarajah
  • 5,758
  • 27
  • 38
  • Thanks for the reply Suvi, (It took me a while to actually see they reply!) I've tried the code but unfortunately it doesn't seem to work... the button has no response – user1441095 Oct 24 '12 at 01:11