37 users online (2 members and 35 guests)  


  Results 1 to 3 of 3

Related

  1. submission form help    Forum: Website Scripts Forum
    Replies: 1
  2. form submission    Forum: Website Scripts Forum
    Replies: 2
  3. Form Submission    Forum: Web Hosting Forum
    Replies: 9
  4. Form Submission    Forum: Website Scripts Forum
    Replies: 2
  5. form submission    Forum: HTML Forum
    Replies: 6
  1. #1
    MrCircuits's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    5

    Question Preventing duplicate form submission

    I have a CGI application that allows the users to add entries into a database from a form. It is possible for the user to click the submit button several times before the confirmation screen is displayed, resulting in the same information being added to the database several times.

    Is there some easy way of preventing the form from being submitted more than once? Is it possible to disable a button once it has been clicked?

    I have tried the following, which seems to work some of the time, but not always...

    In Head section:

    <SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript"><!--
    // Prevent a form from being submitted twice. (Used to prevent double adding)
    function SubmitOnce() {
    if (window.document.CtDetails.SubmitOption.value == 'X') {
    alert("Please wait while the previous request completes.")
    }
    else {
    window.document.CtDetails.Option.value=window.document.CtDetails.SubmitOption.value
    window.document.CtDetails.submit()
    window.document.CtDetails.SubmitOption.value='X'
    }
    }
    //--></SCRIPT>


    In the Form:
    <Input Type=Hidden Name="SubmitOption" Value="*AddCtP">
    <Button Type="Submit" Name="btnAdd" Onclick="SubmitOnce()">
    Add This Entry</Button>&nbsp;

  2. #2
    Zaire's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Mar 2001
    Location
    Hamburg, NY
    Posts
    312
    Quote Originally Posted by MrCircuits
    I have a CGI application that allows the users to add entries into a database from a form. It is possible for the user to click the submit button several times before the confirmation screen is displayed, resulting in the same information being added to the database several times.

    Is there some easy way of preventing the form from being submitted more than once? Is it possible to disable a button once it has been clicked?

    I have tried the following, which seems to work some of the time, but not always...

    In Head section:

    <SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript"><!--
    // Prevent a form from being submitted twice. (Used to prevent double adding)
    function SubmitOnce() {
    if (window.document.CtDetails.SubmitOption.value == 'X') {
    alert("Please wait while the previous request completes.")
    }
    else {
    window.document.CtDetails.Option.value=window.document.CtDetails.SubmitOption.value
    window.document.CtDetails.submit()
    window.document.CtDetails.SubmitOption.value='X'
    }
    }
    //--></SCRIPT>


    In the Form:
    <Input Type=Hidden Name="SubmitOption" Value="*AddCtP">
    <Button Type="Submit" Name="btnAdd" Onclick="SubmitOnce()">
    Add This Entry</Button>&nbsp;
    Alright, this is easy...

    you don't need that much javascript, your form needs to look like so:

    Code:
    <form name="some_form">
    <!-- fields here -->
    <input name="submitbtn" type="submit" value="Submit" onClick="document.some_form.submitbtn.disabled = true">
    I think that should work just fine... im at work so I can exactly check, but give it a try

    - Eric

  3. #3
    MrCircuits's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    5
    Thanks Eric, that works just great.

    Steve