File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes document.formName.filedName problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "document.formName.filedName problem" Watch "document.formName.filedName problem" New topic
Author

document.formName.filedName problem

wei liu
Ranch Hand

Joined: Nov 19, 2008
Posts: 35

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


SCJP 1.6 in 2010
SCWCD5 in 2011
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6


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

Joined: Nov 19, 2008
Posts: 35

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

Joined: Mar 07, 2010
Posts: 38

or simply




AyomaOnline - CodeGreed
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61193
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ayoma Wijethunga
Ranch Hand

Joined: Mar 07, 2010
Posts: 38

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..

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: document.formName.filedName problem