• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Javascript Problem in document.forms

 
Yogendra Joshi
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without indentation, your code is very hard to read. Do you really not indent your code?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a regular expression, there is no need to look at every single character in a loop.

Eric
 
Yogendra Joshi
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

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



Thanks everyone for help,
Yogendra.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic