Gossamer Forum
Home : General : Internet Technologies :

Find the nth element within a form (javascript)

Quote Reply
Find the nth element within a form (javascript)
Here's the code for finding the nth element within a form, it returns the object itself.

function objGetNthElement( varname, instance ) {
var count = 0;
var len = form_name.elements.length;
for ( var i=0; i<len; i++ ) {


// note: remove the "\" characters from the next line

var obj = form_name.elements\[i\];
if ( ( obj.name == varname ) && ( obj.type == 'text' ) ) {
count++;
if ( count == instance ) {
return( obj )
}
}
}
return( null );
}

Last edited by:

srepetti: Jun 11, 2002, 8:28 PM