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
Solved

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?

Posted on 2004-03-25
8
384 Views
Last Modified: 2012-05-04
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
Comment
Question by:aneethat
  • 4
  • 2
  • 2
8 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 10684846
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
 

Author Comment

by:aneethat
ID: 10685048
hi,

       The above button defination gives me javascript syntax error.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10685196
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 7

Expert Comment

by:gam3r_3xtr3m3
ID: 10685284
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
 
LVL 63

Accepted Solution

by:
Zvonko earned 75 total points
ID: 10685313
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
 
LVL 7

Expert Comment

by:gam3r_3xtr3m3
ID: 10685380
oh sorry disregard my post above, i misread the thread... lolx =p
0
 

Author Comment

by:aneethat
ID: 10701006
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
 
LVL 63

Expert Comment

by:Zvonko
ID: 10701709
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Google Maps API and PHP 25 49
Binding a Grid in Javascript 5 43
jQuery force form POST 7 46
what is the best Integrated development environment 2 21
Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

860 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