Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
| Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 16th, 2005, 10:14 AM
Registered User
 
Join Date: Jun 2005
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Autosuggest Textbox by Nicholas Zakas

I'm trying to run the autosuggest textbox example (http://www.webreference.com/programm.../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);
 }
}


 
Old June 16th, 2005, 10:25 AM
nzakas's Avatar
Wrox Author
 
Join Date: Dec 2004
Location: Peabody, MA, USA.
Posts: 217
Thanks: 0
Thanked 5 Times in 5 Posts
Default

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:

Code:
aSuggestions[aSuggestions.length] = this.states[i]
You can also test for the existence of the push() method by doing this:

Code:
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/
 
Old June 16th, 2005, 10:28 AM
Registered User
 
Join Date: Jun 2005
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

"alert(aSuggestions.push)" did return undefined, so I will check for updates. And "aSuggestions[aSuggestions.length] = this.states[i]" did fix it. Thanks.

 
Old June 18th, 2005, 05:48 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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:
Code:
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)
 
Old July 14th, 2005, 07:58 AM
Registered User
 
Join Date: Jul 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old January 13th, 2006, 07:45 AM
Registered User
 
Join Date: Jan 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Nicholas Zakas JavaScript Maintainability video jminatel BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 0 May 25th, 2007 11:48 AM
Nicholas Zakas JavaScript Maintainability video jminatel BOOK: Professional Ajax 2nd Edition ISBN: 978-0-470-10949-6 0 May 25th, 2007 11:47 AM
AutoSuggest and Links gt96 BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 July 4th, 2006 04:58 PM
Converting AutoSuggest textbox to .NET UserControl gulbaek BOOK: Professional Ajax ISBN: 978-0-471-77778-6 7 July 3rd, 2006 10:36 AM
Autosuggest Textbox Issue smay Javascript 3 August 3rd, 2005 02:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.