By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,729 Members | 1,490 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,729 IT Pros & Developers. It's quick & easy.

If given 1 element in an array of textboxes... find which element number it is

P: n/a

I call this Javascript function with "GetEleNum(this)"
passing it 1 of the elements of a text-box array.

Is there a QUICK way to get the "element #"? I'm currently using this
SLOW code.
(It works... but I need something better/faster.)

function GetEleNum(c)
{
// Given 1 element in this textBox array... what is the array element #?

var i;

for(i=0; i<form1.txtBox.length; i++)
if(form1.txtBox[i] == c) return i;

return 0; // Not found
}

Thanks

Nov 15 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Nov 15, 8:59 pm, "\"A_Michigan_User\""
<Michigan_RE_M...@ameritech.netwrote:
I call this Javascript function with "GetEleNum(this)"
passing it 1 of the elements of a text-box array.

Is there a QUICK way to get the "element #"? I'm currently using this
SLOW code.
(It works... but I need something better/faster.)

function GetEleNum(c)
{
// Given 1 element in this textBox array... what is the array element #?

var i;

for(i=0; i<form1.txtBox.length; i++)
if(form1.txtBox[i] == c) return i;

return 0; // Not found

}

Thanks
Try organizing your question into something understandable, PLEASE!
This way, I don't know what you're asking, what you're trying to
accomplish, anything.

Suggestion nr. 1: don't use 'u' instead of 'you', '1' instead of
'one', '#' instead of 'number' etc.
Suggestion nr. 2: explain what specific terms mean, e.g. what your
txtBox's -are-, what 'element #' means
(I suppose it's an ordinal number in an array, but -
what- array, or have you maybe meant
element's ID, etc.
Suggestion nr. 3: the way you're doing it right now - DOESN'T work.
What if the element is on the first place
(index 0)? You'll understand it the same like it
wasn't found, right?

Regards
Nov 15 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.