Hi,

Sorry, typo above.  Where I said

> var forenames = inputs.invoke('getValue');
>
> 'vals' is now an array with the values of all of the forenameX inputs.

I did of course mean 'forenames', not 'vals'.

-- T.J.

On Jun 21, 12:54 pm, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
> Hi Stuart,
>
> The id attribute _must_ be unique within the page, that's part of the
> HTML standard.  You can have multiple inputs with the same name
> attribute, but not the same id.  When adding the further inputs,
> you'll need to give them unique ids like 'forename0', 'forename1',
> 'forename2', etc.  Once they have unique IDs, then you can use $F to
> retrieve them.
>
> In terms of finding the values for all of them, the great thing is
> that Prototype provides CSS3 attribute substring selectors[1] even if
> the underlying browser doesn't.  So you can do this:
>
> var inputs = $$('input[id^=forename]');
>
> ...to get an array of the form elements whose ID _starts with_
> 'forename', although doing it only within the form element might be
> faster:
>
> var inputs = $('myForm').select('input[id^=forename]');
>
> Quite easy to get their values at that point via Enumerable#invoke[2],
> which is mixed in with arrays:
>
> var forenames = inputs.invoke('getValue');
>
> 'vals' is now an array with the values of all of the forenameX inputs.
>
> Naturally you can combine all of this:
>
> var forenames = $('myform').select('input[id^=forename]').invoke
> ('getValue');
>
> [1]http://www.w3.org/TR/css3-selectors/#attribute-substrings
> [2]http://prototypejs.org/api/enumerable/invoke
>
> HTH,
> --
> T.J. Crowder
> tj / crowder software / com
> Independent Software Engineer, consulting services available
>
> On Jun 21, 12:11 pm, Stuart <stuart.ga...@googlemail.com> wrote:
>
> > I have a form that has rows of input fields added using javascript by
> > pressing a button, which means that I have a single form with lots of
> > items with the same ID.  eg.:
>
> > <input id=forename></input>  <input id=surname></input>
> > <input id=forename></input>  <input id=surname></input>
> > <input id=forename></input>  <input id=surname></input>
> > <input id=forename></input>  <input id=surname></input>
>
> > [button to add a new line of input fields]  [button to call a
> > javascript to save the form]
>
> > When the user presses the [save] button, my Javascript works fine for
> > all my non-repeated fields, but I can't figure out how to get a list
> > of values for <forename> and <surname>
>
> > I guess it shoud be something like:
>
> > var my_forenames = $F( 'forname' );
> > var my_surnames = $F( 'surname' );
>
> > ....but this just returns the value of the first row.
>
> > What SHOULD I be doing?
>
> > TIA
>
> > Stuart
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to