Rails use the form field names like: mymodel[myfield] And I want to change one fiel with javascript, how I get/set this form fields? I trayed: document.myform.myform[''myfield''].value document.myform.myform[myfield].value document.myform.myform.myfield.value but it don''t work, what is the correct way to get/set this form fields? Thank you !
Try: document.myform[''myfield''].value On Apr 5, 2005 12:18 PM, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote:> > Rails use the form field names like: mymodel[myfield] > And I want to change one fiel with javascript, how I get/set this form > fields? > I trayed: > document.myform.myform[''myfield''].value > document.myform.myform[myfield].value > document.myform.myform.myfield.value > but it don''t work, what is the correct way to get/set this form fields? > > Thank you ! > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- rick http://techno-weenie.net
Hi, Rails use the form field names like: mymodel[myfield] And I want to change one fiel with javascript, how I get/set this form fields? I trayed: document.myform.myform[''myfield''].value document.myform.myform[myfield].value document.myform.myform.myfield.value but it don''t work, what is the correct way to get/set this form fields? Thank you ! -- Pedro C. Valentini pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org +55 (21) 8708-8035
On Apr 5, 2005 12:18 PM, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote:> > > Rails use the form field names like: mymodel[myfield] > And I want to change one fiel with javascript, how I get/set this form > fields? > I trayed: > document.myform.myform.myfield.valueVery close: document.myform.myfield.value = ''foo''; Drew -- ---------------------------------------------------------------- Drew Taylor * Web development & consulting Email: drew-sYRLyna/r5E+Va1GwOuvDg@public.gmane.org * Site implementation & hosting Web : www.drewtaylor.com <http://www.drewtaylor.com> * perl/mod_perl/DBI/mysql/postgres ---------------------------------------------------------------- _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
I think he had a typo in his email. I believe he meant to write, I trayed:> document.myform.mymodel[''myfield''].value > document.myform.mymodel[myfield].value > document.myform.mymodel.myfield.value >The problem is that the form names have the []''s in them so you can''t just do document.myform.mymodel[myfield].value because javascript expects an array when it sees the []''s and it gets all confused.. I think this might work though: document.myform["mymodel[myfield]"].value not definitely sure, but it seems like it should. I never understood why Rails chose to use that notation on the field names. I think using dot noation wouldn''t been better .. like mymodel.myfield.. but what do I know. On Apr 5, 2005 3:08 PM, Drew Taylor <taylor.andrew.j-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On Apr 5, 2005 12:18 PM, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote: > > > > > > Rails use the form field names like: mymodel[myfield] > > And I want to change one fiel with javascript, how I get/set this form > > fields? > > I trayed: > > document.myform.myform.myfield.value > > > Very close: document.myform.myfield.value = ''foo''; > > Drew > -- > ---------------------------------------------------------------- > Drew Taylor * Web development & consulting > Email: drew-sYRLyna/r5E+Va1GwOuvDg@public.gmane.org * Site implementation & hosting > Web : www.drewtaylor.com <http://www.drewtaylor.com> * > perl/mod_perl/DBI/mysql/postgres > ---------------------------------------------------------------- > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- - Ramin http://www.getintothis.com/blog _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Tue, 05 Apr 2005 14:18:25 -0300, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote:>Rails use the form field names like: mymodel[myfield] >And I want to change one fiel with javascript, how I get/set this form >fields?I''m very new to Rails so hope I''m not missing something that Rails may do with the standard HTML ID attribute but you could always try something like this: <input type="text" name="whatever[whatever]" id="idField" (etc) > then.. <script type="text/javascript"> var elField = document.getElementById(''idField''); alert(''Value = '' + elField.value); elField.value = ''something else''; </script> Regards, Andrew
Use the id of the form element: (With prototype.js enabled:) $(''mymodel_myfield'').value thomas Am 07.04.2005 um 13:41 schrieb Michael Champanis:> Try this: > > alert(document.myform.myform_myfield); or > alert(document.forms[0].myform_myfield.value); > > Michael > > > > Hi, > > Rails use the form field names like: mymodel[myfield] > And I want to change one fiel with javascript, how I get/set this form > fields? > I trayed: > document.myform.myform[''myfield''].value > document.myform.myform[myfield].value > document.myform.myform.myfield.value > but it don''t work, what is the correct way to get/set this form fields? > > Thank you ! > > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Try this: alert(document.myform.myform_myfield); or alert(document.forms[0].myform_myfield.value); Michael> Hi, > > Rails use the form field names like: mymodel[myfield] > And I want to change one fiel with javascript, how I get/set this form > fields? > I trayed: > document.myform.myform[''myfield''].value > document.myform.myform[myfield].value > document.myform.myform.myfield.value > but it don''t work, what is the correct way to get/set this form fields? > > Thank you ! >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails