Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

document.formName.filedName problem

 
wei liu
Ranch Hand
Posts: 35
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everyone,

Is there a way I can pass the name of form as an argument in an function . example code is list belows



which "add_employee" is the form name

I noticed that the formName in "document.formName.fieldName" must be literately the form's name such as "<form name="formName">" to let it work.
my question is : is there away to replace the formName to an variable, so other page can use this function just simplely pass their form's name as arg in the js function.

thanks very much
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


You want to use the array notation, not the dot notation






Better yet, you can use an id on the form/element and use getElementById

Eric
 
wei liu
Ranch Hand
Posts: 35
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:

You want to use the array notation, not the dot notation






Better yet, you can use an id on the form/element and use getElementById

Eric




Thanks erics, it works.!!
 
Ayoma Wijethunga
Ranch Hand
Posts: 38
Firefox Browser IntelliJ IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or simply



 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64844
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ayoma Wijethunga wrote:or simply

How is that more simple than by id? ids, not names, are the best way to identify elements in the DOM. Using names is antiquated and fragile.
 
Ayoma Wijethunga
Ranch Hand
Posts: 38
Firefox Browser IntelliJ IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Ayoma Wijethunga wrote:or simply

How is that more simple than by id? ids, not names, are the best way to identify elements in the DOM. Using names is antiquated and fragile.


Yes 100% agreed, but the original question was,

Is there a way I can pass the name of form as an argument in an function


So providing the solution with an ID selector seems not to be related. That's why..

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic