aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Javascript Problem in document.forms 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 "Javascript Problem in document.forms" Watch "Javascript Problem in document.forms" New topic
Author

Javascript Problem in document.forms

Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
Hi Ranchers,

Recently, I came across a condition in our application where we had multiple forms in a single jsp and we had to validate special characters for title field. we had 2 Title fields name linkTitle and fileTitle. Something which i got from google and customized for our behaviour is as follows :



Now, What i am trying to do in the above is calling the special character function with a formName and fieldName which should get replaced at runtime and validate the said field, viz linkTitle if formName is addLinkForm and fileTitle if form name is uploadFileForm.

Some this piece of code isnt working and it always gives an error saying "document.formName.FieldName is undefined" , Can someone please help me on this since i need to get this working.

Thanks in advance,
Yogendra N Joshi.


Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Without indentation, your code is very hard to read. Do you really not indent your code?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Using document.formName.fieldName is a very old-fashined way to address the elements.

Step into the modern era, assign each field an id, and use document.getElementById() to locate it.

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Use a regular expression, there is no need to look at every single character in a loop.

Eric
Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
Hi ,

Thanks for the reply. I have this regex and its special characters for matching up but it always returns false even if it contains special character or it doesnt. Please check this.


Please help me on this guys,

thanks.
Yogendra
Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
Hi Guys,

I am done with the validation. I used Regex as suggested and my validation works wonders.



Thanks everyone for help,
Yogendra.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javascript Problem in document.forms