473,765 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combining object arrays

If I have 2 object arrays like:

var txtobj = theform.getElem entsByTagName(" input");
var selobj = theform.getElem entsByTagName(" select");

and i want to iterate over them I'd like to combine them and then
iterate over them.

so I would do something like this below, but that doesn't look right.
var bothobj = txtobj+selobj;

for( var i=0; i<bothobj.lengt h; i++ )
{
do something....
}

Any thought?

Sep 14 '05 #1
10 7046
mike said the following on 9/14/2005 4:37 PM:
If I have 2 object arrays like:

var txtobj = theform.getElem entsByTagName(" input");
var selobj = theform.getElem entsByTagName(" select");

and i want to iterate over them I'd like to combine them and then
iterate over them.

so I would do something like this below, but that doesn't look right.
var bothobj = txtobj+selobj;

for( var i=0; i<bothobj.lengt h; i++ )
{
do something....
}

Any thought?


Test it and see.

..concat()

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Sep 14 '05 #2
mike wrote:
If I have 2 object arrays like:

var txtobj = theform.getElem entsByTagName(" input");
var selobj = theform.getElem entsByTagName(" select");


Bad!!
var txtobj = document.thefor m.getElementsBy TagName("input" )

But why not use DOM 0?

function checkInputsAndS elects(form){
var f=form.length;
while(f--){
if(form[f].type.toLowerCa se()=="input"){
// do stuff with input
}
if(form[f].type.toLowerCa se()=="select") {
// do stuff with select
}
}
}

Mick

[...]
Sep 14 '05 #3
Mick,

Why is this bad?

var txtobj = document.thefor m.getElementsBy TagName("input" )

Is it because you think it only gets <input ..> but not <INPUT ...>

Mike

Sep 14 '05 #4
mike wrote:
Mick,

Why is this bad?

var txtobj = document.thefor m.getElementsBy TagName("input" )

Is it because you think it only gets <input ..> but not <INPUT ...>


var txtobj = theform.getElem entsByTagName(" input");

missing "document" reference...

Will work in IE, though.

Mick
Sep 14 '05 #5
i had already defined

var theform = document.update ;

so ... it is ok then ... ?

Sep 14 '05 #6
mike wrote:
If I have 2 object arrays like:

var txtobj = theform.getElem entsByTagName(" input");
var selobj = theform.getElem entsByTagName(" select");

and i want to iterate over them I'd like to combine them and then
iterate over them.

so I would do something like this below, but that doesn't look right.
var bothobj = txtobj+selobj;
No, it's not right. getElementsByTa gName returns an HTML collection,
not an array. Collections have some array-like properties, e.g. length,
but have none of an Array's methods.

for( var i=0; i<bothobj.lengt h; i++ )
{
do something....
}


To concatenate collections, you could create a concatenation function
that adds the elements of a collection to an array[1]:

function concatCollectio ns() {
var c, k, j, i = arguments.lengt h;
var a = [];
for ( j=0; j<i; j++ ) {
c = arguments[j];
h = c.length;
for ( k=0; k<h; k++ ){
a.push(c[k]);
}
}
return a;
}

And once you've created the collections, call the above function:

var arrayOfElements = concatCollectio ns(txtobj, selobj);

But this seems a waste of time. Whatever function that is going to
iterate over the array could accept multiple arguments and iterate over
collections instead.

Unless there are some array methods you'd like to use.

[1] Push is not supported in very old browsers (it was introduced in
JavaScript 1.2, works in Netscape 3+ and IE 5+ I think), it's pretty
simple to create your own push function if required.
<URL:http://developer.mozil la.org/en/docs/Core_JavaScript _1.5_Reference: Global_Objects: Array:push>
--
Rob
Sep 15 '05 #7
mike wrote:
i had already defined

var theform = document.update ;

so ... it is ok then ... ?

Your original post:

<QUOTE>
If I have 2 object arrays like:

var txtobj = theform.getElem entsByTagName(" input");
var selobj = theform.getElem entsByTagName(" select");

[...]
</QUOTE>

Missing "document" reference.
Mick
Sep 15 '05 #8
But this seems a waste of time. Whatever function that is going to
iterate over the array could accept multiple arguments and iterate over

collections instead.

I agree. thanks though for your explanation and collection code.

Mike

Sep 15 '05 #9
Lee
mike said:

If I have 2 object arrays like:

var txtobj = theform.getElem entsByTagName(" input");
var selobj = theform.getElem entsByTagName(" select");

and i want to iterate over them I'd like to combine them and then
iterate over them.


You're probably handling the input's and the select's differently
anyway, so why bother with pulling them out and concatinating them?

for (i=0;i<theform. elements.length ;i++) {
if (theform.elemen ts[i].type=="input") {
} else if (...) {
...
}
}

Sep 15 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
10693
by: Phil Powell | last post by:
if (is_array($_POST)) { foreach ($this->getAssocSectionsObjArray($key, $dbAP) as $obj) { print_r($obj); print_r(" in array? "); print_r(in_array($obj, $result)); print_r("<P>"); if (!in_array($obj, $result)) array_push($result, $obj); } }
2
3276
by: Chris Mullins | last post by:
I've spent a bit of time over the last year trying to implement RFC 3454 (Preparation of Internationalized Strings, aka 'StringPrep'). This RFC is also a dependency for RFC 3491 (Internationalized Domain Names / IDNA) which is something that I also need to support. The problem that I've been struggling with in .NET is that of Unicode Code Points > 0xFFFF. These points are encoded into UTF8 using the Surrogate Pair encoding scheme that...
38
5228
by: VK | last post by:
Hello, In my object I have getDirectory() method which returns 2-dimentional array (or an imitation of 2-dimentional array using two JavaScript objects with auto-handled length property - please let's us do not go into an "each dot over i" clarification discussion now - however you want to call - you call it ;-) array contains records of all files in the current dir. array contains records of all subs in the current dir
3
2228
by: Flip | last post by:
I'm looking at the O'Reilly Programming C# book and I have a question about extending and combining interfaces syntax. It just looks a bit odd to me, the two syntaxes look identical, but how does C# know which is extending and which is combining? interface IStorable{ void Read(); void Write(object o); }
1
1168
by: Mr. Jingles | last post by:
Hi, anyone have any thoughts on combining two 2-Dimensional arrays into one. Thanx
1
2068
by: ferraro.joseph | last post by:
Hi, I'm querying Salesforce.com via their AJAX toolkit and outputting query results into a table. Currently, their toolkit does not possess the ability to do table joins via their structured query language, which forces me to do the join manually via arrays. Right now, I'm having trouble getting these query results (which are in
1
1401
by: Jeff | last post by:
I have two array: var Array1=new Array(); Array1=,,]; Array1=,,]; var Array2=new Array(); Array2=,,];
6
3448
by: tshad | last post by:
I am looking for a way to combine 2 string arrays. I am trying to get a list of files from 2 directories and combine them: string strFiles; string strFiles2; strFiles = Directory.GetFiles(Settings.ArchiveFilePath, "*.*"); strFiles2 = Directory.GetFiles(Settings.ExceptionFilePath, "*.*");
8
1598
by: rodeored | last post by:
I don't know what the official programming lingo is for this situation but there probably is one. I have arrays, which happen to be parsed urls, and I want to make one big array with each subarray in the big array representing one directory. Sometimes the path has no sub directories, sometimes 1 or 2 etc . For example here are 2 example arrays: $patharr Array ( =>
0
9568
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
9404
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
8833
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
7381
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
6651
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
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.