input[] array validation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jason Morehouse

    input[] array validation

    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[]'];



    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
    --
    Jason Morehouse
    Vendorama - The evolution of e-commerce

  • Martin Honnen

    #2
    Re: input[] array validation



    Jason Morehouse wrote:

    [color=blue]
    > 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.htm...elect-multiple
    >
    > But that doesn't actually work, for me.[/color]

    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.

    --

    Martin Honnen

    Comment

    • Mick White

      #3
      Re: input[] array validation

      Jason Morehouse wrote:[color=blue]
      > 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.htm...elect-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?[/color]

      if(variableLeng th = 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

      Comment

      Working...