Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] Form with array like structure
- From: mwarden at gmail.com (Matt Warden)
- Subject: [Javascript] Form with array like structure
- Date: Sun Jul 23 17:57:43 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-----
- References:
- [Javascript] Form with array like structure
- From: Peter Lauri
- [Javascript] Form with array like structure
- From: Steve Clason
- [Javascript] Form with array like structure
- Prev by Date: [Javascript] Form with array like structure
- Next by Date: [Javascript] Paste images
- Previous by thread: [Javascript] Form with array like structure
- Next by thread: [Javascript] Paste images
- Index(es):