Problems with onSubmit

Hey guys I have a problem with the onSumbit event of my form which used to work correctly. Heres the code

onSubmit="return validateOnSubmit()"

      function validateOnSubmit(){
            var errors = 0;
            if (!document.forms.addClub.county){
                  return false;
            }else{
                  if (!validateEmail(document.forms.addClub.email, 'inf_email')) errors += 1;
                  if (!isURL(document.forms.addClub.webSite,'inf_website')) errors += 1;
                  if (!validateTelnr(document.forms.addClub.telephoneNo,'inf_phone', true)) errors += 1;
                  if (!validateMenu(document.forms.addClub.county, 'inf_county')) errors += 1;
                  if (!validatePresent(document.forms.addClub.cityTown,'inf_city')) errors += 1;
                  if (!validatePresent(document.forms.addClub.clubAddress,'inf_address')) errors += 1;
                  if (!validateMenu(document.forms.addClub.country, 'inf_country')) errors += 1;
                  if (!validateMenu(document.forms.addClub.activity, 'inf_activity')) errors += 1;
                  if (!validatePresent(document.forms.addClub.motivatingMateID,'inf_mateID')) errors += 1;
                  if (!validatePresent(document.forms.addClub.nameofclub,'inf_name')) errors += 1;
                  if (!validateCheckbox(document.forms.addClub.tandc, 'inf_tandc')) errors += 1;
                  return (errors == 0);
            }
      }

each function within the validateOnSubmit() function works fine for each form element when their onchange event fires so I know the functions work i.e. isURL, validateMenu etc. So I don't understand why if one of the inputs is incorrect the form will still submit. ANyone have any ideaS?
LVL 7
levyukAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nabsolCommented:
Hi

Use this code

function validateOnSubmit(){
          var errors = 0;
          if (!document.forms[0].addClub.county){
               return false;
          }else{
               if (!validateEmail(document.forms[0].addClub.email, 'inf_email')) errors += 1;
               if (!isURL(document.forms[0].addClub.webSite,'inf_website')) errors += 1;
               if (!validateTelnr(document.forms[0].addClub.telephoneNo,'inf_phone', true)) errors += 1;
               if (!validateMenu(document.forms[0].addClub.county, 'inf_county')) errors += 1;
               if (!validatePresent(document.forms[0].addClub.cityTown,'inf_city')) errors += 1;
               if (!validatePresent(document.forms[0].addClub.clubAddress,'inf_address')) errors += 1;
               if (!validateMenu(document.forms[0].addClub.country, 'inf_country')) errors += 1;
               if (!validateMenu(document.forms[0].addClub.activity, 'inf_activity')) errors += 1;
               if (!validatePresent(document.forms[0].addClub.motivatingMateID,'inf_mateID')) errors += 1;
               if (!validatePresent(document.forms[0].addClub.nameofclub,'inf_name')) errors += 1;
               if (!validateCheckbox(document.forms[0].addClub.tandc, 'inf_tandc')) errors += 1;
               if (errors == 0)
               {
                    return true;
               }
               else
              {
                   return false;
              }
          }
     }

Hope this works!

By Nab

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nabsolCommented:
Hi

Sorry I think addclub is your form name so try this

function validateOnSubmit(){
          var errors = 0;
          if (!document.addClub.county){
               return false;
          }else{
               if (!validateEmail(document.addClub.email, 'inf_email')) errors += 1;
               if (!isURL(document.addClub.webSite,'inf_website')) errors += 1;
               if (!validateTelnr(document.addClub.telephoneNo,'inf_phone', true)) errors += 1;
               if (!validateMenu(document.addClub.county, 'inf_county')) errors += 1;
               if (!validatePresent(document.addClub.cityTown,'inf_city')) errors += 1;
               if (!validatePresent(document.addClub.clubAddress,'inf_address')) errors += 1;
               if (!validateMenu(document.addClub.country, 'inf_country')) errors += 1;
               if (!validateMenu(document.addClub.activity, 'inf_activity')) errors += 1;
               if (!validatePresent(document.addClub.motivatingMateID,'inf_mateID')) errors += 1;
               if (!validatePresent(document.addClub.nameofclub,'inf_name')) errors += 1;
               if (!validateCheckbox(document.addClub.tandc, 'inf_tandc')) errors += 1;
               if (errors == 0)
               {
                    return true;
               }
               else
              {
                   return false;
              }
          }
     }




OR



function validateOnSubmit(){
          var errors = 0;
          if (!document.forms[0].county){
               return false;
          }else{
               if (!validateEmail(document.forms[0].email, 'inf_email')) errors += 1;
               if (!isURL(document.forms[0].webSite,'inf_website')) errors += 1;
               if (!validateTelnr(document.forms[0].telephoneNo,'inf_phone', true)) errors += 1;
               if (!validateMenu(document.forms[0].county, 'inf_county')) errors += 1;
               if (!validatePresent(document.forms[0].cityTown,'inf_city')) errors += 1;
               if (!validatePresent(document.forms[0].clubAddress,'inf_address')) errors += 1;
               if (!validateMenu(document.forms[0].country, 'inf_country')) errors += 1;
               if (!validateMenu(document.forms[0].activity, 'inf_activity')) errors += 1;
               if (!validatePresent(document.forms[0].motivatingMateID,'inf_mateID')) errors += 1;
               if (!validatePresent(document.forms[0].nameofclub,'inf_name')) errors += 1;
               if (!validateCheckbox(document.forms[0].tandc, 'inf_tandc')) errors += 1;
               if (errors == 0)
               {
                    return true;
               }
               else
              {
                   return false;
              }
          }
     }

By Nab


levyukAuthor Commented:
Ok cool ill try those. Is there any reason why my code shouldn't work?
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

nabsolCommented:
Hi levyuk

1. Can you post here how you call the function for individual form elements i.e.    onchange="....."

2. Have you written form tag like this

<form name="addClub"  onSubmit="return validateOnSubmit()"> or <form id="addClub"  onSubmit="return validateOnSubmit()">

By Nab
levyukAuthor Commented:
Form:

<form class="form" onSubmit="return validateOnSubmit()" style="width:100%" method="post" name="addClub" action="processClub.php">

Elements:

<input class="form" type="text" name="nameofclub" id="nameofclub" onChange="validatePresent(this, 'inf_name');">
levyukAuthor Commented:
I found the problem, was a bloody copy/paste error of mine. Cheers for your help, you can have points for helping me even though the answer isn't there.

Thanks
J
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.