Javascript form submit function submits the update page two times, so i get dublicate record in a table. What is the error in my javascript form submit function?

Hi,

         I am using javascript function to submit the form. It submits the form two times i.e. update two similar records (dublicate) at a time.

But if i take out the javascript function calling from Submit button and put the action in the form tag it works fine i.e. update one record at a time.

Here is my javascript function with form tag and submit button.

function saveFinalValidate(msg){      
                 if (checkMandatoryInput() == true && window.confirm (msg)==true){                                  document.f.action = "Adminsubmitted.asp?Status=S";
            document.f.submit();
            return true;
      }
      else
      return false;      
}

<form name=f method=post>
<input name=Submit type=submit value=submit onclick=""javascript:return saveFinalValidate('This action will submit the proposal.');"">

But if i take Change the form tag and Submit button it works fine.

<form name=f method=post action="Adminsubmitted.asp?status=S' onsubmit= "return checkMandatoryInput();">

<input type=submit value=submit>

Could anyone tell what is the error in the javascript function that submits the page two times.

aneethatAsked:
Who is Participating?
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.

ZvonkoSystems architectCommented:
The error are your quotas.

<input name=Submit type=submit value=submit onclick="return saveFinalValidate('This action will submit the proposal.');">

Even better would be to make that button regular button.
Like this:
<input name=Submit type=button value=Submit onclick="saveFinalValidate('This action will submit the proposal.');">



0
aneethatAuthor Commented:
hi,

       The above button defination gives me javascript syntax error.
0
ZvonkoSystems architectCommented:
Ok, you did not show the complete page. When your button is printed out as string (in ASP), then you need double quotas.
Can we see the complete page?

0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

gam3r_3xtr3m3Commented:
the script should be:

function saveFinalValidate(msg){    
     if(checkMandatoryInput() == true && window.confirm (msg)==true){
          document.f.action = "Adminsubmitted.asp?Status=S";
          document.f.submit();
          return false;
     }
     else{
          return true;
     }
}

0
ZvonkoSystems architectCommented:
Here a tested version:

<html>
<head>
<script>
function saveFinalValidate(msg){  
  if (checkMandatoryInput() == true && window.confirm (msg)==true){
    document.f.action = "Adminsubmitted.asp?Status=S";
    return true;
  } else {
    return false;    
  }
}
function checkMandatoryInput(){
  return true;
}
</script>
</head>
<form name=f method=post action="test">
<input name=Submit type=submit value=Submit onclick="return saveFinalValidate('This action will submit the proposal.');">
</form>
</body>
</html>




0

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
gam3r_3xtr3m3Commented:
oh sorry disregard my post above, i misread the thread... lolx =p
0
aneethatAuthor Commented:
Hi ZVonko,

                 It's working fine. Thank you. What is the reason you took out the form submit, i.e document.f.submit();.

In normal practice though we put the form action we include the form submit function as well then why it submits the form two times.

May i know the reason why?

Thank you very much.
0
ZvonkoSystems architectCommented:
Of course.

The reason is when you return true from the checking function, then is the form submitted anyway.
If you do form.submit() inside the function, then you have to return false.
But then does the button type=submit make no sense. Better choice would be then: type=button



0
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.