Solved

Form validation - multiple fields with the same name not validating properly

Posted on 2003-11-14
8
313 Views
Last Modified: 2008-02-26
I have a form that generates dynamically depending on what is chosen from several dropdowns. This form sometimes generates only 1 data field (txtQFound) and sometimes up to 10 datafields all having the same name (txtQFound).

My JS form validation is not validating this field, perhaps because most of the time there are multiple? How do I do this? I have this validating 6 other fields and the rest of the fields are validating properly.

Current JS validation code (only the field in question):

function validate() {
    errorFields='';
    errorMessage='';
    vQFound=frmQASort.txtQFound.value;

if (vQFound=='') {
         errorFields+=' Quantity Found\n';
         event.returnValue=false;     }

if (errorFields!='') {
         errorMessage+=' The following fields are required:\n\n';
         errorMessage+=errorFields;
         alert(errorMessage);     }}
0
Comment
Question by:Mustangz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 10

Accepted Solution

by:
Bustarooms earned 80 total points
ID: 9748856
function validate() {
   errorFields='';
   errorMessage='';
   vQFound=frmQASort.txtQFound.value;

var theEl = frmQASort.txtQFound;
for(i=0; i < theEl.length; i++){
if (theEl[i].value=='') {
        errorFields+=' Quantity Found\n';
        event.returnValue=false;     }
}

if (errorFields!='') {
        errorMessage+=' The following fields are required:\n\n';
        errorMessage+=errorFields;
        alert(errorMessage);     }}
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9748928
>>>event.returnValue=false;

Will not work for Netscape

use return false instead
0
 

Author Comment

by:Mustangz
ID: 9748998
This is an internal app, and we only use IE.

I'll go try this and let you know what happens.. thanks for the quick response.
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

Author Comment

by:Mustangz
ID: 9749024
Works like a charm... thank you much Bustarooms.
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9749037
Ok just as long as everyone uses IE your fine.

Good Job Busta
0
 
LVL 10

Expert Comment

by:Bustarooms
ID: 9749040
actually it doesn't

if there is only one field than it will not work cause a problem

give me a sec and ill post a fix
0
 
LVL 10

Expert Comment

by:Bustarooms
ID: 9749060
function validate() {
   errorFields='';
   errorMessage='';
   vQFound=frmQASort.txtQFound.value;

  var theEl = frmQASort.txtQFound;
  if(theEl.length){
      for(i=0; i < theEl.length; i++){
         if (theEl[i].value=='') {
           errorFields+=' Quantity Found\n';
           event.returnValue=false;     }
      }
   }
   else{
       if (theEl.value=='') {
         errorFields+=' Quantity Found\n';
         event.returnValue=false;     }
   }

if (errorFields!='') {
        errorMessage+=' The following fields are required:\n\n';
        errorMessage+=errorFields;
        alert(errorMessage);     }
}
0
 

Author Comment

by:Mustangz
ID: 9749139
Of course you were right.. I tried it with just one and it didn't validate, but then used your update fix and it does work no matter the number of input fields..

I appreciate you being so thorough, and posting the fix.

thanks again!
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question