• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Javascript Problem in document.forms

 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without indentation, your code is very hard to read. Do you really not indent your code?
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
When people don’t understand what you are doing they call you crazy. But this tiny ad just doesn't care:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic