Loading ...
Sorry, an error occurred while loading the content.
 

Autocomplete - problems with itemSelectEvent

Expand Messages
  • dunxwbl
    I need autocomplete to fill a hidden field for me, just like here: http://tech.groups.yahoo.com/group/ydn-javascript/auth?
    Message 1 of 3 , Mar 26, 2007
      I need autocomplete to fill a hidden field for me, just like here:
      http://tech.groups.yahoo.com/group/ydn-javascript/auth?
      check=G&done=http%3A%2F%2Ftech%2Egroups%2Eyahoo%2Ecom%2Fgroup%2Fydn-
      javascript%2Fmessage%2F6434

      I have 2.2.0a and I'm using itemSelectEvent in an example based on
      the delivered ysearch_flat.html example:

      ---
      var myInput = document.getElementById('ysearchinput0');
      var myContainer = document.getElementById('ysearchcontainer0');
      oAutoComp0 = new YAHOO.widget.AutoComplete
      (myInput,myContainer,oACDS);
      oAutoComp0.queryDelay = 0.5;
      oAutoComp0.maxResultsDisplayed = 20;
      oAutoComp0.minQueryLength = 3;
      oAutoComp0.formatResult = function(oResultItem, sQuery) {
      var sPlace = oResultItem[0];
      var nInfo = oResultItem[1];
      var hidden_var = oResultItem[2]
      var aMarkup = ["<div id='ysearchresult'><div class='ysearchquery'>",
      nInfo,
      hidden_var,
      "</div>",
      sPlace,
      "</div>"];
      return (aMarkup.join(""));
      };
      oAutoComp0.itemSelectEvent.subscribe(setLocId);
      var setLocId = function(oSelf,listItem,dataArray) {
      var id = listItem[2]
      document.getElementById("loc_id").value = id
      }
      ---

      The pick list diplayed includes "hidden_var" fine, so I know it's
      being returned, but the logger always tells me:

      global:

      'fn' is null or not an object
      (http://www.mydomain.com/test/ysearch_flat.html, line 1544)

      Presumably just a lack of Javascript understanding on my part, but
      does anybody got any ideas as my brain has started to melt?

      Cheers
      Dunx
    • Jason Erickson
      You need to subscribe to the function after it has been created. JavaScript is not compiled, so it is just executed in order. At the time you subscribe, there
      Message 2 of 3 , Mar 26, 2007
        You need to subscribe to the function after it has been created.
        JavaScript is not compiled, so it is just executed in order. At the
        time you subscribe, there is no setLocId function, so you just pass
        undefined.

        --- In ydn-javascript@yahoogroups.com, "dunxwbl" <duncan@...> wrote:
        >
        > I need autocomplete to fill a hidden field for me, just like here:
        > http://tech.groups.yahoo.com/group/ydn-javascript/auth?
        > check=G&done=http%3A%2F%2Ftech%2Egroups%2Eyahoo%2Ecom%2Fgroup%2Fydn-
        > javascript%2Fmessage%2F6434
        >
        > I have 2.2.0a and I'm using itemSelectEvent in an example based on
        > the delivered ysearch_flat.html example:
        >
        > ---
        > var myInput = document.getElementById('ysearchinput0');
        > var myContainer = document.getElementById('ysearchcontainer0');
        > oAutoComp0 = new YAHOO.widget.AutoComplete
        > (myInput,myContainer,oACDS);
        > oAutoComp0.queryDelay = 0.5;
        > oAutoComp0.maxResultsDisplayed = 20;
        > oAutoComp0.minQueryLength = 3;
        > oAutoComp0.formatResult = function(oResultItem, sQuery) {
        > var sPlace = oResultItem[0];
        > var nInfo = oResultItem[1];
        > var hidden_var = oResultItem[2]
        > var aMarkup = ["<div id='ysearchresult'><div
        class='ysearchquery'>",
        > nInfo,
        > hidden_var,
        > "</div>",
        > sPlace,
        > "</div>"];
        > return (aMarkup.join(""));
        > };
        > oAutoComp0.itemSelectEvent.subscribe(setLocId);
        > var setLocId = function(oSelf,listItem,dataArray) {
        > var id = listItem[2]
        > document.getElementById("loc_id").value = id
        > }
        > ---
        >
        > The pick list diplayed includes "hidden_var" fine, so I know it's
        > being returned, but the logger always tells me:
        >
        > global:
        >
        > 'fn' is null or not an object
        > (http://www.mydomain.com/test/ysearch_flat.html, line 1544)
        >
        > Presumably just a lack of Javascript understanding on my part, but
        > does anybody got any ideas as my brain has started to melt?
        >
        > Cheers
        > Dunx
        >
      • juliusdietz
        Hi dunxwbl , was wha Jason wrote the reason why it didn t work? I ve got the same problem and doing it the other way round doesn t help... Thanks for any
        Message 3 of 3 , Apr 2, 2007
          Hi "dunxwbl",

          was wha Jason wrote the reason why it didn't work?
          I've got the same problem and doing it the other way round doesn't help...
          Thanks for any help!!

          Julius

          --- In ydn-javascript@yahoogroups.com, "Jason Erickson" <jason@...> wrote:
          >
          > You need to subscribe to the function after it has been created.
          > JavaScript is not compiled, so it is just executed in order. At the
          > time you subscribe, there is no setLocId function, so you just pass
          > undefined.
          >
          > --- In ydn-javascript@yahoogroups.com, "dunxwbl" <duncan@> wrote:
          > >
          > > I need autocomplete to fill a hidden field for me, just like here:
          > > http://tech.groups.yahoo.com/group/ydn-javascript/auth?
          > > check=G&done=http%3A%2F%2Ftech%2Egroups%2Eyahoo%2Ecom%2Fgroup%2Fydn-
          > > javascript%2Fmessage%2F6434
          > >
          > > I have 2.2.0a and I'm using itemSelectEvent in an example based on
          > > the delivered ysearch_flat.html example:
          > >
          > > ---
          > > var myInput = document.getElementById('ysearchinput0');
          > > var myContainer = document.getElementById('ysearchcontainer0');
          > > oAutoComp0 = new YAHOO.widget.AutoComplete
          > > (myInput,myContainer,oACDS);
          > > oAutoComp0.queryDelay = 0.5;
          > > oAutoComp0.maxResultsDisplayed = 20;
          > > oAutoComp0.minQueryLength = 3;
          > > oAutoComp0.formatResult = function(oResultItem, sQuery) {
          > > var sPlace = oResultItem[0];
          > > var nInfo = oResultItem[1];
          > > var hidden_var = oResultItem[2]
          > > var aMarkup = ["<div id='ysearchresult'><div
          > class='ysearchquery'>",
          > > nInfo,
          > > hidden_var,
          > > "</div>",
          > > sPlace,
          > > "</div>"];
          > > return (aMarkup.join(""));
          > > };
          > > oAutoComp0.itemSelectEvent.subscribe(setLocId);
          > > var setLocId = function(oSelf,listItem,dataArray) {
          > > var id = listItem[2]
          > > document.getElementById("loc_id").value = id
          > > }
          > > ---
          > >
          > > The pick list diplayed includes "hidden_var" fine, so I know it's
          > > being returned, but the logger always tells me:
          > >
          > > global:
          > >
          > > 'fn' is null or not an object
          > > (http://www.mydomain.com/test/ysearch_flat.html, line 1544)
          > >
          > > Presumably just a lack of Javascript understanding on my part, but
          > > does anybody got any ideas as my brain has started to melt?
          > >
          > > Cheers
          > > Dunx
          > >
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.