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

I have the following code: f

Status
Not open for further replies.

tboerner

Programmer
Oct 19, 2001
23
US
I have the following code:

for (myItem in document.forms["Invoices"].elements) {

alert(myItem);
alert(myItem.type);

if (myItem.type == "checkbox") {
// never gets here
}
}

myItem.type is undefined for all the elements. But alert(myItem) returns the name of the elements.

How come 'type' doesn't work?
 
I've never actually seen that notation before myItem 'in'.
Anyway you could just rewrite the script to:

var i;
var myItem = document.Invoices.elements
var FormFields = myItem.length;
for (i=0;i<FormFields; i++) {

alert(myItem.name);
alert(myItem.type);

if (myItem.type == &quot;checkbox&quot;) {
alert(&quot;Im a checkbox!&quot;);
}
}
 
sorry those last few lines should say

alert(myItem.name);
alert(myItem.type);

if (myItem.type == &quot;checkbox&quot;) {
alert(&quot;Im a checkbox!&quot;);
}
 
Thanks. I didn't bother with MyItem. I ended up doing something like this, as you suggested.

for (idx=0; idx < document.forms[&quot;Invoices&quot;].elements.length; ++idx) {

if (document.forms[&quot;Invoices&quot;].elements[idx].type == &quot;checkbox&quot;) {

// process check box code here

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top