PermaLink Preventing users from clicking on Submit (or any button) more than once06/15/2006 03:38 PM
Category : Show-n-Tell Thursday
Location : Columbus, Ohio, USA
Problem:
       Users in their impatience click submit a second or third time resulting in multiple saves of the dcoument.

Solution:
       Hide the button after it has been clicked and then do validation and submission.

  1. In the code where the submit button is put in a span tag that can be used to hide the button later.
    (NOTE: The HTML should be pass-through - the button should not be pass-through)

            <span id="SubmitButton"> [[BUTTON GOES HERE]] </span>

  2. The submit button should call a JavaScript method like: userPressedSubmit()

  3. Put in a second span that can be displayed during the validation and submit.

            <span id="SubmitInProcess" style="display:none">Submit in process please wait.</span>

  4. In the JS Header, include resource "jsTsFormulas.js" or include it as a page, etc.
    Oh, right, you are (probably) not a Teamwork team member so you do not have access to our tools library. So here are the two functions you need to add to your JS Header

            function tsHideObject(objNameStr, documentObj){
                    // hides a specified object (such as a ). documentObj is optional
                    if (documentObj) {
                            if (typeof documentObj == "object"){
                                    documentObj.getElementById(objNameStr).style.display = "none";
                            } else {
                                    alert("CODE ERROR: The second parameter of tsHideObject must be an object representing the document on which you want to unhide an element. For the current document, you may leave it blank.");
                            }
                    } else {
                            if (document.getElementById(objNameStr)){
                                    document.getElementById(objNameStr).style.display = "none";
                            }
                    }
            }


           function tsShowObject(objNameStr, documentObj){
                  // unhides a specified object (such as a ). documentObj is optional
                  if (documentObj) {
                         if (typeof documentObj == "object"){
                                documentObj.getElementById(objNameStr).style.display = "block";
                         } else {
                                alert("CODE ERROR: The second parameter of tsShowObject must be an object representing the document on which you want to unhide an element. For the current document, you may leave it blank.");
                         }
                  } else {
                         if (document.getElementById(objNameStr)){
                                document.getElementById(objNameStr).style.display = "block";
                         }
                  }
           }
  5. In the JS Header, add these functions

    function userPressedSubmit() {
            tsHideObject("SubmitButton");
            tsShowObject("SubmitInProcess")
            window.setTimeout("nowDoValidationAndSubmit()", 1)
    }

    function nowDoValidationAndSubmit() {
            // do your validation
            if (validationFails) {
                    alert("Validation has failed");
                    tsShowObject("SubmitButton");
                    tsHideObject("SubmitInProcess")
            } else {
                    // validation was a success
                    document.forms[0].submit()
            }

    }

This page has been accessed 658 times. .
Comments :v

1. Rich Waters11/07/2006 01:07:04 PM
Homepage: http://www.rich-waters.com/blog/


<form name="blah" onsubmit="document.getElementById('submitButton').disabled = true">
<input type="submit" id="submitButton">
</form>




Post a comment ^


Email addresses provided are not made available on this site.





You can use UUB Code in your posts.

[b]bold[/b]  [i]italic[/i]  [u]underline[/u]  [s]strikethrough[/s]

URL's will be automatically converted to Links


:-x :cry: :laugh: :cool: :-( :huh: :rolleyes: :grin: :-p :angry: :-D ;-) :-) :-\ :lips: :emb: :-o
bold italic underline Strikethrough





Remember me    

Add Manual Trackback
Please enter the details of the trackback post. Your trackback will not appear on the site until it has been verified. This won't be immediate, as trackbacks are validated on a scheduled basis. Be patient.











Useful Links
Contact Me
Calendar
February 2012
Su
Mo
Tu
We
Th
Fr
Sa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Planet Lotus
By Category
The BlogRoll
Monthly Archive
Lotus Domino ND6 RSS News Feed RSS Comments Feed RSS Validator Blog Admin Lotus Geek Open Notes Picture Database OpenNTF CoComment Integrated BlogSphere
Powered by
Blogsphere