• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 425
  • Last Modified:

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.

0
aneethat
Asked:
aneethat
  • 4
  • 2
  • 2
1 Solution
 
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now