Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

control arrays?

Status
Not open for further replies.

BeanDog

Programmer
Jul 15, 2000
60
US
Is it possible in DHTML (vbs or js) to create a control array a la VB? Like a bunch of textboxes that are tb[0], tb[1], tb[2], etc? [sig][/sig]
 
Yes you can. However, all of the controls are accessible already through document.forms['formname'].controlname.

Maybe you want to do something that just grabs the text boxes on a page. This is one way you could do it:

function getTextboxes(form_name) {

var tb=new Array();
var i,j;

for (i=0,j=0;i<document.forms[form_name].elements.length;++i) {
if (document.forms[form_name].elements.type==&quot;text&quot;) {
tb[j++]=document.forms[form_name].elements;
}
}
return tb;
}

This is a pretty basic example, but it should illustrate the point. If you assign the return value of getTextBoxes to a variable, you can then access that variable to make changes to a given text box (the variable holds a reference to the actual text box).

HTH,

[sig]<p>Russ<br><a href=mailto:bobbitts@hotmail.com>bobbitts@hotmail.com</a><br><a href= is in</a><br>[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top