Enrique Barraorion
2006-Oct-04 11:47 UTC
datetime_select generates html code that I can''t have access
Hello: <%= datetime_select ''datetime''+@indice.to_s, ''end_date'' , :start_year => 2006%> generates: <TD colspan=2 ><select name="datetime0[end_date(1i)]"> <option value="2006" selected="selected">2006</option> <option value="2007">2007</option> <option value="2008">2008</option> <option value="2009">2009</option> <option value="2010">2010</option> <option value="2011">2011</option> </select> <select name="datetime0[end_date(2i)]"> <option value="1">January</option> <option value="2">February</option> <option value="3">March</option> .... And I want to access the value that the user has selected. I have tried with document.form_event.datetime0[end_date(1i)] but javascript gives me an error: "missing ) after argument list" just after the (1i) any idea thanks in advance -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Chris Mear
2006-Oct-04 14:50 UTC
Re: datetime_select generates html code that I can''t have access
Enrique Barraorion wrote:> <%= datetime_select ''datetime''+@indice.to_s, ''end_date'' , :start_year => > 2006%> > > generates: > <select name="datetime0[end_date(1i)]"> > > And I want to access the value that the user has selected. I have tried > with > document.form_event.datetime0[end_date(1i)] > but javascript gives me an error: "missing ) after argument list" just > after the (1i)I''ve just been grappling with this. The problem is that JavaScript expects you to use the IDs of elements to reference them, not the names. But when Rails generates these ''select'' tags, it only sets the ''name'' attribute, and as far as I can see there''s no easy way to set the ''id'' attribute. Ideally, if you could generate a select tag that looked like this: <select name="datetime0[end_date(1i)]" id="datetime0_end_date_1i"> then you could grab it in JavaScript with document.getElementById(''datetime0_end_date_1i"); (Notice that names can contain funny characters like ''['', '']'', ''('' and '')'', whereas IDs don''t). Alternatively, it is possible to select an element by its name, but it involves cycling through elements to find it. For example, if you''re using the Prototype JavaScript library, you can do something like var selects = $(''my_form'').getElementsByTag(''select''); for (var i = 0; i < selects.length; i++) { var select = selects[i]; if (select.name == "datetime0[end_date(1i)]") { alert(select.value); } } assuming that your form has an ID like <form action="..." id="my_form"> But I''m sure you''ll agree that''s hardly elegant. Chris --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2006-Oct-04 16:09 UTC
Re: datetime_select generates html code that I can''t have access
> <%= datetime_select ''datetime''+@indice.to_s, ''end_date'' , :start_year => > 2006%> > > generates: > <TD colspan=2 ><select name="datetime0[end_date(1i)]"> > <option value="2006" selected="selected">2006</option> > <option value="2007">2007</option> > <option value="2008">2008</option> > <option value="2009">2009</option> > > <option value="2010">2010</option> > <option value="2011">2011</option> > </select> > <select name="datetime0[end_date(2i)]"> > <option value="1">January</option> > <option value="2">February</option> > <option value="3">March</option> > .... > > And I want to access the value that the user has selected. I have tried > with > document.form_event.datetime0[end_date(1i)] > but javascript gives me an error: "missing ) after argument list" just > after the (1i) > any idea > thanks in advanceI think something like this would work... document.form_event.elements["datetime0[end_date(1i)]"].xxxxxxx -philip --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Enrique Barraorion
2006-Oct-04 16:35 UTC
Re: datetime_select generates html code that I can''t have ac
Philip Hallstrom wrote:>> <option value="2010">2010</option> >> document.form_event.datetime0[end_date(1i)] >> but javascript gives me an error: "missing ) after argument list" just >> after the (1i) >> any idea >> thanks in advance > > I think something like this would work... > > document.form_event.elements["datetime0[end_date(1i)]"].xxxxxxx > > -philipThank you very much. That worked very well. I would have never realized about it thanks thanks thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Chris Mear
2006-Oct-04 17:55 UTC
Re: datetime_select generates html code that I can''t have access
Philip Hallstrom wrote:> document.form_event.elements["datetime0[end_date(1i)]"].xxxxxxxHoly crap, that''s fantastic. How have I managed to not notice this before? Thanks! Chris --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---