Link to home
Start Free TrialLog in
Avatar of aneethat
aneethat

asked on

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.

Avatar of Zvonko
Zvonko
Flag of North Macedonia image

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.');">



Avatar of aneethat
aneethat

ASKER

hi,

       The above button defination gives me javascript syntax error.
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?

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;
     }
}

ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oh sorry disregard my post above, i misread the thread... lolx =p
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.
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