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