Prevent Premature clicking on a submit button while page is refreshed

Discussion in 'Javascript' started by anonieko@hotmail.com, Aug 14, 2005.

  1. Guest

    Scenario: You have a page that is TOO slow to refresh.
    But it allows partial flushing of html contents. I.e.
    Submit button already appears but you don't
    want your users to click on it prematurely
    because other parts are still coming.


    Here I put a javascript the will enable only
    submit button only after 5 seconds after the page
    is load fully.

    The prevention of button being clicked twice
    is also done .


    <html>
    <head>
    </head>
    <body>

    <form id="testForm" >
    <input id="test" type=text>
    <input type=button value="1click only" onclick="dosubmit()">
    </form>



    <script type="text/javascript">
    <!--
    var submitted = false;
    var timer1=setTimeout('EnableClick()', 5000);

    function EnableClick() {
    if (typeof submitted == 'undefined') return false;
    submitted = false;
    }

    function dosubmit(method) {
    // prevent clicking twice
    if (typeof submitted == 'undefined') return false;
    if ( submitted ) return false;
    submitted = true;
    clearTimeout(timer1);
    document.testForm.submit();
    }
    -->
    </script>


    </body
     
    , Aug 14, 2005
    #1
    1. Advertising

  2. RobG Guest

    wrote:
    > Scenario: You have a page that is TOO slow to refresh.
    > But it allows partial flushing of html contents. I.e.
    > Submit button already appears but you don't
    > want your users to click on it prematurely
    > because other parts are still coming.
    >


    How about using script to prevent submission say by disabling the submit
    button. Then have an onload function that enables it.

    Your method makes submission of the form dependent on JavaScript, which
    it should not be, and makes users wait some arbitrary time that you
    think might let the page load fully. Why 5 seconds? Some users will
    have to wait longer than necessary, others will likely still not have
    the form fully loaded.

    >
    > Here I put a javascript the will enable only
    > submit button only after 5 seconds after the page
    > is load fully.


    From the script below, you attempt to wait for 5 seconds after the
    script is loaded, not when the page has finished loading. Your script
    does not prevent submission anyway.

    >
    > The prevention of button being clicked twice
    > is also done .


    That should be handled at the server, not the client, and your script
    does not guarantee only one submit.

    >
    > <html>
    > <head>
    > </head>
    > <body>
    >
    > <form id="testForm" >
    > <input id="test" type=text>
    > <input type=button value="1click only" onclick="dosubmit()">
    > </form>
    >
    >
    >
    > <script type="text/javascript">
    > <!--


    HTML comments in script elements are completely unnecessary and possibly
    harmful, don't use them.

    > var submitted = false;
    > var timer1=setTimeout('EnableClick()', 5000);
    >
    > function EnableClick() {
    > if (typeof submitted == 'undefined') return false;


    'submitted' is defined as 'false', this test will always return false.

    > submitted = false;
    > }
    >
    > function dosubmit(method) {
    > // prevent clicking twice
    > if (typeof submitted == 'undefined') return false;


    'submitted' is never undefined, this test will always return false.

    > if ( submitted ) return false;
    > submitted = true;
    > clearTimeout(timer1);
    > document.testForm.submit();


    This method of accessing form elements fails in Firefox, you need to
    either give the form a name (testForm would be good) or use:

    document.forms['testForm'].submit();

    [...]

    --
    Rob
     
    RobG, Aug 15, 2005
    #2
    1. Advertising

  3. Guest

    That is exactly the opinion I wanted! Great!
     
    , Aug 15, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Brett
    Replies:
    4
    Views:
    11,785
    James Brett
    Nov 26, 2003
  2. Buddy Ackerman

    Disable button to prevent double clicking

    Buddy Ackerman, Feb 27, 2006, in forum: ASP .Net
    Replies:
    10
    Views:
    60,804
  3. Network-Man
    Replies:
    5
    Views:
    78,853
    gaul1
    Jul 7, 2012
  4. Kuldeep
    Replies:
    1
    Views:
    896
    Mark Rae
    May 29, 2007
  5. ljlolel
    Replies:
    2
    Views:
    519
Loading...

Share This Page