Rails names its form fields as model[field] , but you can''t access the value in javascript by document.form.model[field].value. How do you escape the [''s to access the value? -- Posted via http://www.ruby-forum.com/.
If you''re using prototype, you can use $(''model_field'').value -Thomas Am 08.03.2006 um 21:19 schrieb rmb:> Rails names its form fields as model[field] , but you can''t access the > value in javascript by document.form.model[field].value. How do you > escape the [''s to access the value? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
rmb wrote:> Rails names its form fields as model[field] , but you can''t access the > value in javascript by document.form.model[field].value. How do you > escape the [''s to access the value?I haven''t tested this, but I believe you would do: document.form[''model[field]''].value The other thing you could do is use the form field''s ID value, with a getElementById DOM call: element = getElementById(''model_field'') This assumes, of course, that you have unique IDs for all your form elements. -Brian
Brian V. Hughes wrote:> rmb wrote: >> Rails names its form fields as model[field] , but you can''t access the >> value in javascript by document.form.model[field].value. How do you >> escape the [''s to access the value? > > I haven''t tested this, but I believe you would do: > > document.form[''model[field]''].value > > The other thing you could do is use the form field''s ID value, with a > getElementById DOM call: > > element = getElementById(''model_field'') > > This assumes, of course, that you have unique IDs for all your form > elements. > > -BrianThe second one works. The first one gives a javascript "has no properties" error -- Posted via http://www.ruby-forum.com/.