Hi there, I''m trying to fectch value of input for comparison. But return an empty value even if the value is non empty... Here is the (problematic) part of my code (prototype 1.6.0.2) : [JAVASCRIPT CODE] var countUser = 3; for(var i = countUsers; i > 0; i--) { var testUser = $(''username[''+ countUsers +'']'').value; // OR var testUser = $F(''username[''+ countUsers +'']''); // OR var testUser = document.getElementById(''username[''+ countUsers +'']'').value; alert(countUsers +" :: "+ testUser +" == "+ myUser); } It says for exemple : 1 :: == John Paul Jones !!! The input value is never shown ! Any ideas ? Thank you for your help David --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hey David, I am a little confused on what you''re trying to do, but if you''re trying to collect the values of the form fields, try using the $F function, it simplifies the operation you''re attempting. Try testing this snippet and see what you can come up with. var arr = []; for(var i = count; i > 0; i--) { arr.push($F("username["+count+"]")); arr should now be an array string values from the form elements you''re looking for, Remember using name and id on an element can be tricky, if you''re using both make sure they''re the same value. On May 5, 9:43 am, ahseed <david.cuelol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi there, > > I''m trying to fectch value of input for comparison. But return an > empty value even if the value is non empty... > > Here is the (problematic) part of my code (prototype 1.6.0.2) : > > [JAVASCRIPT CODE] > var countUser = 3; > for(var i = countUsers; i > 0; i--) { > var testUser = $(''username[''+ countUsers +'']'').value; > // OR var testUser = $F(''username[''+ countUsers +'']''); > // OR var testUser = document.getElementById(''username[''+ countUsers > +'']'').value; > alert(countUsers +" :: "+ testUser +" == "+ myUser); > > } > > It says for exemple : 1 :: == John Paul Jones !!! > The input value is never shown ! > > Any ideas ? > > Thank you for your help > > David--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
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 for(var i = countUsers; i > 0; i--) { arr.push($F("username["+countUsers+"]")); } 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... 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); arr.push($F("username["+myCounter+"]")); } alert(arr); > SAME RESULT ! Javascript is a warm gun ! Any ideas ? Thank you for your help ! On 5 mai, 17:28, Matt Foster <mattfoste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey David, > > I am a little confused on what you''re trying to do, but if > you''re trying to collect the values of the form fields, try using the > $F function, it simplifies the operation you''re attempting. Try > testing this snippet and see what you can come up with. > > var arr = []; > for(var i = count; i > 0; i--) { > arr.push($F("username["+count+"]")); > > arr should now be an array string values from the form elements you''re > looking for, Remember using name and id on an element can be tricky, > if you''re using both make sure they''re the same value. > > On May 5, 9:43 am, ahseed <david.cuelol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi there, > > > I''m trying to fectch value of input for comparison. But return an > > empty value even if the value is non empty... > > > Here is the (problematic) part of my code (prototype 1.6.0.2) : > > > [JAVASCRIPT CODE] > > var countUser = 3; > > for(var i = countUsers; i > 0; i--) { > > var testUser = $(''username[''+ countUsers +'']'').value; > > // OR var testUser = $F(''username[''+ countUsers +'']''); > > // OR var testUser = document.getElementById(''username[''+ countUsers > > +'']'').value; > > alert(countUsers +" :: "+ testUser +" == "+ myUser); > > > } > > > It says for exemple : 1 :: == John Paul Jones !!! > > The input value is never shown ! > > > Any ideas ? > > > Thank you for your help > > > David--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On May 6, 8:09 pm, ahseed <david.cuelol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 > lastnameYou 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---