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
380 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Auto Submit on dropdown box 3 35
Accessing property value in an object. 1 18
C3-->D3 Line Chart 4 17
getting id from database 5 24
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now