473,659 Members | 3,605 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using an array's extended properties in jQuery

25 New Member
What does one have to do in the code below to allow jQuery to make use of the find() function that I added to the array object (see line #26)?

Is there a namespace clash?

The code is here http://jsbin.com/oluyu6/5/edit

Thanks.

Expand|Select|Wrap|Line Numbers
  1.   Array.prototype.find = function(searchStr) {  
  2.      // http://www.hunlock.com/blogs/Mastering_Javascript_Arrays#quickIDX39
  3.      var returnArray = false;  
  4.      for (i=0; i<this.length; i++) {
  5.              if (typeof(searchStr) == 'function') {
  6.                  if (searchStr.test(this[i])) {
  7.                      if (!returnArray) {     returnArray = [];  }
  8.                      returnArray.push(i);      
  9.                  }    
  10.              } else {
  11.                if (this[i]===searchStr) {
  12.                    if (!returnArray) { returnArray = []; }
  13.                  returnArray.push(i);      
  14.              }    
  15.          }  
  16.      }  
  17.      return returnArray;
  18.  };
  19.  
  20. function toggleArrowBySelectedVal(option_array, list_id, arrow)
  21. {
  22.   var list=$("#"+list_id);
  23.  
  24.   var numselected=$("#"+list_id+" option:selected").length;
  25.   if ( (numselected==1)   &&
  26.      (option_array.find(Number(list.value))))  arrow.disabled=false;
  27.   else                      arrow.disabled=true;
  28.  
  29. }
  30.  
Apr 14 '11 #1
1 1837
Dormilich
8,658 Recognized Expert Moderator Expert
list.value is undefined, because list is a jQuery instance and not a <select>.

besides that you have a logic error (line #6), if searchStr is a function, searchStr.test( ) will throw an error (undefined method call). functions only have the methods apply(), bind(), call() & toString().
Apr 14 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
3625
by: Frank Stephan | last post by:
Hi, im using Struts with nested tags for form validation. So I end up with form elements named like this risikenManuell.praemieNeu risikenManuell.praemieNeu .... I would like to do a calculation on the input values
1
28421
by: Suresh | last post by:
Hi, How to set the TextBox text property using Reflection. Or to that matter any property of a control. Iam having trouble writing a function of the style public static void SetPropertyValue(Object target, string property_name(as the text or width), object propertyvalue) { target - get type; type- property of given name;
3
1259
by: Martiankeeper | last post by:
Here is my problem... Let us say I have two classes, each representing a database table. ( won't go into methods for loading / saving . etc .. that is not m problem) Code ------------------- class HairColourClass
0
848
by: darrel | last post by:
Thanks to some help from Karl yesterday, I've discovered the use of Interfaces to allow usercontrols to communicate information between them using the Interface as the 'parent' rather than the aspx class. I don't quite understand properties, though. ;o) This is what I have thus far: I declared a interface:
11
1207
by: darrel | last post by:
Karl pointed me towards the use of interfaces to share information between controls. I'm getting the hang of it, but still running into some logic/syntax problems. What I'm trying to do is have a usercontrol set a property. I then want the parent page to read that property, and set a new property defined within an interface. I then want ANOTHER usercontrol to be able to access that property from the interface. Ultimately, I want one...
9
2410
by: Mario Vázquez | last post by:
Hi, I have a component which exposes an extended property. I want to edit this property using a UITypeEditor. The problem is that when the designer raises my UITypeEditor sends a reference of the component it's being edited (a TextBox for example) but not of my component. How can I receive a reference of the component that owns the extended property? Thanks a lot,
4
1172
by: mark | last post by:
(windows app not web) I have a procedure to populate a given datagrid (Datagrid1) with a dataset from an indexed data connection. It works: Globals: Dim FileName1 As String Dim DS As System.Data.DataSet Dim OleDbConnection1(20) As System.Data.OleDb.OleDbConnection Dim OleDbDataAdapter1(20) As System.Data.OleDb.OleDbDataAdapter Dim CurrentIndex As Integer = 0
0
954
by: MattBell | last post by:
I have a drop down list control which I want to have automatically add a null item to. So I extended DropDownList and tried to have it add an item to the control on the performdatabind function. But the item was always being overwritten, so I tried to use the AppendDataBoundItems property to make it work, but it seems to go into an infinite loop every time it hits the AppendDataBoundItems = true statement. IE it restarts the databinding...
3
3559
by: Ben | last post by:
Hi! I have a user on my database that has only "select" access (db_datareader). Problem is, I also want him to also be able to create/update extended properties on tables or views, but without modifying the tables' schema. I played around with GRANT but apparently, a member of "db_datareader" cannot create/modify extended properties on an object if he's not the owner of this object. I tried making this user a member of
2
4738
OraMaster
by: OraMaster | last post by:
Hi All, Below is the SQL of one view in my DB. SELECT cxc.cst_key AS q37_individual_key, dbo.co_individual.ind_cst_key AS q37_related_ind_key, dbo.co_individual.ind_prf_code AS q37_prf_code, dbo.co_individual.ind_first_name AS q37_first_name, dbo.co_individual.ind_last_name AS q37_last_name, dbo.co_individual.ind_mid_name AS q37_ind_mid_name, dbo.co_individual.ind_sfx_code AS...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8337
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8628
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7359
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.