[Javascript] Form with array like structure
Matt Warden
mwarden at gmail.com
Sun Jul 23 17:57:46 CDT 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Steve Clason wrote:
> Peter Lauri wrote:
>> Yes that helps, I can see that I have 14 elements and that is correct.
>> However, I have not been able to loop thru them? How do I do that? I
>> tried
>> the following:
>>
>> var inputelements = document.getElementsByTagName("input");
>>
>> for(var i=0, len=inputelements.length; i<len; i++) {
>> document.write(inputelements[i].value+"<br>");
>> }
>>
>> But that did not work :/
>
> Try:
>
> var inputelements = document.getElementsByTagName("input");
>
> for(var i=0, i<inputelements.length; i++) {
> document.write(inputelements[i].value+"<br>");
> }
This is actually an equivalent loop, just a different way of writing it.
Peter, there is nothing wrong with your loop. I believe it is actually
working properly, but you cannot see this because of how you are trying
to show the results. Try this, just for the heck of it:
var valuestr = '', inputs = document.getElementsByTagName('input');
for (var i=0; i<inputs.length; i++) {
valuestr += inputs.item(i).value;
}
alert(valuestr);
- --
Matt Warden
Cleveland, OH, USA
http://mattwarden.com
This email proudly and graciously contributes to entropy.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFEw/7qrI3LObhzHRMRAiO+AJ9j9x1l3zHNTOJFynwM1UuxW6sqOQCfSYMb
uweCYE+d3a93+rUmkIiErCY=
=/zpY
-----END PGP SIGNATURE-----
More information about the Javascript
mailing list