input[] array validation

  • Thread starter Jason Morehouse
  • Start date
J

Jason Morehouse

Hello...

I need to get the values (for validation) of a php style html input array:

<input type="file" name="image[]">
<input type="file" name="image[]">
<input type="file" name="image[]">
<input type="file" name="image[]">

The PHP faq gives an example:

variable = documents.forms[0].elements['var[]'];

http://ca3.php.net/manual/en/faq.html.php#faq.html.select-multiple

But that doesn't actually work, for me.

What would be the proper way to loop through each of the upload inputs
and get the value?

Thanks,
-J
 
M

Martin Honnen

Jason Morehouse wrote:

I need to get the values (for validation) of a php style html input array:

<input type="file" name="image[]">
<input type="file" name="image[]">
<input type="file" name="image[]">
<input type="file" name="image[]">

The PHP faq gives an example:

variable = documents.forms[0].elements['var[]'];

http://ca3.php.net/manual/en/faq.html.php#faq.html.select-multiple

But that doesn't actually work, for me.

Be more specific about what happens, do you get a script error?
The access to
document.forms[0].elements['image[]']
with those inputs above being inside of the first <form> on the page
should indeed yield a collection with a length property through which
you can loop.
 
M

Mick White

Jason said:
Hello...

I need to get the values (for validation) of a php style html input array:

<input type="file" name="image[]">
<input type="file" name="image[]">
<input type="file" name="image[]">
<input type="file" name="image[]">

The PHP faq gives an example:

variable = documents.forms[0].elements['var[]'];

http://ca3.php.net/manual/en/faq.html.php#faq.html.select-multiple

But that doesn't actually work, for me.

What would be the proper way to loop through each of the upload inputs
and get the value?

if(variableLength = documents.forms[0].elements['var[]'].length);

It's not a select-multiple, its type is file, but js should provide a
collection, try it.
Mick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top