On May 6, 8:09 pm, ahseed <[EMAIL PROTECTED]> wrote:
> Hi Matt,
>
> I'm trying to compare values to avoid a person to be present twice in
> the list !
>
> I've already tried the $F function with no success...
> Trying your code (putting in an array) give me (with 3 iteration)
>
> var arr = [];
> // countUser == 3 and input fields are filled with firstname and
> lastname

You mean countUsers = 3


> for(var i = countUsers; i > 0; i--) {

Above you used countUser, here it is countUsers - a typo perhaps?  The
above will iterate over elements with id's username[3], username[2]
and username[1], is that what you want?


>     arr.push($F("username["+countUsers+"]"));}

The value being decremented is i, not countUsers, so:

      arr.push($F("username["+ i +"]"));}


> alert(arr);
>
> > ,, <
>
> I just tried to do this :
>
> alert($F("username[1]")); and then it works !!!
>
> So the problem could come from the type of iterator, should it be a
> string...

Array indexes are strings, however javascript will convert whatever
you provide as an index to a string.  There is no need to use say:

  arr['3']

rather than

  arr[3];

and the second is more efficient.


> Trying to force a string before passing the argument as below
>
> var arr = [];
> // countUser == 3 and input fields are filled with firstname and
> lastname
> for(var i = countUsers; i > 0; i--) {
>     var myCounter = new String(countUsers);

That will create a String object, not a string primitive.  If
conversion to a string was required (and it isn't) it's more efficient
to use:

  var myCounter = '' + i;

i.e. use string concatenation and javascript's automatic type
conversion to generate a string variable.


>     arr.push($F("username["+myCounter+"]"));}
>
> alert(arr); > SAME RESULT !

Because that wasn't the problem.


--
Rob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to