Question

I cannot figure out why this isn't working. It's a JQuery search box that uses the Freebase API to find games. When I POST, the gameID and gameName are blank.

<link type="text/css" rel="stylesheet" href="http://freebaselibs.com/static/suggest/1.3/suggest.min.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://freebaselibs.com/static/suggest/1.3/suggest.min.js"></script>
<script type="text/javascript">
      $(function() {
        $("#game-search").suggest({type:'/games/game'}).bind("fbSelect", function(e, data) {
        $("#game-id").val(data.id);
        $("#game-name").val(data.name);
        });
      });
</script>


<form name="input" action="/game-profile" method="post">
  <input class="search-box" name="fbSelect" type="text" id="game-search"/>
  <input type="hidden" name="gameID" id="game-id" />
  <input type="hidden" name="gameName" id="game-name" />
  <input class="button" value="Go" type="submit"/>
</form>
Was it helpful?

Solution

I grabbed your code and changed the hidden fields to type="text" just so I could see the data when a selection was made from the auto-complete. The fields weren't being populated on select, so I took a quick peek at the API.

It looks like the event you should be binding to is fb-select rather than fbSelect a la:

  $(function() {
    $("#game-search").suggest({type:'/games/game'}).bind("fb-select", function(e, data) {
    $("#game-id").val(data.id);
    $("#game-name").val(data.name);
    });
  });

OTHER TIPS

It doesn't look like the fbSelect event you're binding to, ever gets fired. Have you included all required code parts for this to work?

(Answered retrospectively via comment on original question. @borkweb is more correct.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top