Subject: Autosuggest Textbox by Nicholas Zakas
Posted By: smay Post Date: 6/16/2005 10:14:07 AM
I'm trying to run the autosuggest textbox example (http://www.webreference.com/programming/javascript/ncz/column2/example2.html) in IE6 SP1 but getting "Object doesn't support this property or method" on line 7 of the following function ("aSuggestions.push(this.states[i]);").  Can anyone give a suggestion?

StateSuggestions.prototype.requestSuggestions = function (oAutoSuggestControl) {
 var aSuggestions = [];
 var sTextboxValue = oAutoSuggestControl.textbox.value;
 if (sTextboxValue.length > 0){
  for (var i=0; i < this.states.length; i++) {
   if (this.states[i].indexOf(sTextboxValue) == 0) {
    aSuggestions.push(this.states[i]);
   }
  }
  oAutoSuggestControl.autosuggest(aSuggestions);
 }
}


Reply By: nzakas Reply Date: 6/16/2005 10:25:12 AM
That's very odd. I'm also using IE6 SP1 and it seems to be working fine. If it's failing on the push() method for some reason, you can try changing that line to:

aSuggestions[aSuggestions.length] = this.states[i]


You can also test for the existence of the push() method by doing this:

alert(aSuggestions.push)


If that returns undefined, then for some reason your IE's JavaScript engine is corrupted (it's rare, but I've seen it happen). You may want to try installing all of the available IE updates to see if that fixes the problem.

Nicholas C. Zakas
Author, Professional JavaScript for Web Developers (ISBN 0764579088)
http://www.nczonline.net/
Reply By: smay Reply Date: 6/16/2005 10:28:47 AM
"alert(aSuggestions.push)" did return undefined, so I will check for updates.  And "aSuggestions[aSuggestions.length] = this.states[i]" did fix it.  Thanks.

Reply By: joefawcett Reply Date: 6/18/2005 5:48:03 AM
If push is not working then you have two choices, for your own machine you have a fairly old version of JScript installed. Try downloading the latest version of JScript/Windows Script Host from msdn.com/scripting.

To allow for other people in the same situation you can have this code towards the start of your script block:

if (!Array.prototype.push)
  {
    Array.prototype.push = function(value){this[this.length] = value; return this.length};
  }


If you feel so inclined you can implement the pop method as well...



--

Joe (Microsoft MVP - XML)
Reply By: florianb Reply Date: 7/14/2005 7:58:33 AM
hi there,

i tried to modify the textbox to be able to enter more than only one word but i failed until now. does anybody have an idea how to be able to manage that?

thanks

florianb

Reply By: xfan Reply Date: 1/13/2006 6:45:49 AM
hi guys,

is there a way to add two of these boxes on one page. i assume the first box's ID is txt1, if i make the second one txt2, how would i modify to the java code to work properly.

Thanks guys


Go to topic 38684

Return to index page 396
Return to index page 395
Return to index page 394
Return to index page 393
Return to index page 392
Return to index page 391
Return to index page 390
Return to index page 389
Return to index page 388
Return to index page 387