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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Arrays 1

Status
Not open for further replies.

MikeyK

Programmer
Jul 29, 2001
7
AU
Just wondering if anyone knows if there is a way to make a dynamic array from checkbox id's

for example, 4 check boxes on a page with id's from cbo3706 to cb03709, requires the array:

var a = ("cbo3706","cbo3707","cbo3708","cbo3709")

but what if there are 5 checkboxes on the page
- the array needs to be:

var a = ("cbo3706","cbo3707","cbo3708","cbo3709","cbo3710")

Is there any way I can get the amount of text boxes onLoad of the page, and build the array dynamically ?

any suggestions would be appreciated.
 
Hello,
I'm guessing some things, but see the code below:
<HTML>
<HEAD>
<TITLE> Checkbox </TITLE>
<script>
function buildarray(frm) {
//alert(frm.elements.length);
//alert(frm.elements[0].type);
arr = new Array;
for (elm=0; elm<frm.elements.length; elm ++) {
if (frm.elements[elm].type == &quot;checkbox&quot;) arr[elm] = frm.elements[elm].id;
alert(arr[elm]);
}
}
</script>
</HEAD>

<BODY onLoad=&quot;buildarray(document.myForm)&quot;>
<form name=&quot;myForm&quot;>
<input type=&quot;checkbox&quot; id=&quot;cbo3706&quot; name=&quot;cbo3706&quot;>cbo3706<br>
<input type=&quot;checkbox&quot; id=&quot;cbo3707&quot; name=&quot;cbo3707&quot;>cbo3707<br>
<input type=&quot;checkbox&quot; id=&quot;cbo3708&quot; name=&quot;cbo3708&quot;>cbo3708<br>
<input type=&quot;checkbox&quot; id=&quot;cbo3709&quot; name=&quot;cbo3709&quot;>cbo3709<br>
<!--input type=&quot;checkbox&quot; id=&quot;cbo3710&quot; name=&quot;cbo3710&quot;>cbo3710<br-->
</form>
</BODY>
</HTML>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top