Results 1 to 7 of 7

Thread: Delay on submit button

  1. #1
    Join Date
    Jan 2007
    Posts
    58
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default Delay on submit button

    Hello, i have a form wich submits info to a mssql db, the problem is, i need some script to make the submit button have a delay on show up, i mean, i want to make the users wait at least 1 minute before submit the info, so i was thinking of this way, i know its possible, i've seen it before on some site.

    Thank you.

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    You can have a small JS code snippet which will show the submit button after the user reaches the last form field or rather if the user enters complete information. The using setTimeout JS function you can enable/display the submit button, in the meantime you can also give some "Please wait, Loading...." message on the screen. If you are looking for this kind of functionality confirm it and I'll give you a demo page...

  3. #3
    Join Date
    Jan 2007
    Posts
    58
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by codeexploiter View Post
    You can have a small JS code snippet which will show the submit button after the user reaches the last form field or rather if the user enters complete information. The using setTimeout JS function you can enable/display the submit button, in the meantime you can also give some "Please wait, Loading...." message on the screen. If you are looking for this kind of functionality confirm it and I'll give you a demo page...
    Yes please, more than a form, it has only 1 field, and the submit button, so, even if as soon as you load the page, it starts the countdown would be ok.

    Thank you.

  4. #4
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Have a look at the following code, the submit button will be displayed after one minute of complete DOM loading.
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    	<head>
    		<title>Untitled Document</title>		
    		<style type="text/css">
    		.off{
    			visibility: hidden;
    		}
    		.on {
    			visibility: visible;
    		}	
    		</style>
    		<script type="text/javascript">
    			window.onload = function(){
    				setTimeout(function(){
    					document.getElementById('submit').className = 'on';
    				},1000);
    			}
    		</script>
    	</head>
    	<body>
    		<form name="f" action="" method="get">
    			<label>Name </label> <input type="text" name="fname" id="fname" /><br />
    			<input type="submit" name="submit" id="submit" value="submit" class="off"/>
    		</form>
    	</body>
    </html>
    Please note that if you have multiple JS functions that make use of window.onload event, then you have to club them together as it will execute only one.

  5. The Following User Says Thank You to codeexploiter For This Useful Post:

    nicksalad (05-31-2008)

  6. #5
    Join Date
    Jan 2007
    Posts
    58
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default Little Upgrade

    Can some one please upgrade the script from above to show a countdown while the button is not visible? When the countdown reaches 0 the submit button shows up. Also after click should be nice that instead of poof, disappear it would say loading or something...

    Sorry, real newbie at js.

    Thank you.
    Last edited by nicksalad; 02-17-2009 at 12:05 PM.

  7. #6
    Join Date
    Jan 2007
    Posts
    58
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    Some one? Please...

  8. #7
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Here it is

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
        <head>
            <title>Untitled Document</title>
            <style type="text/css">
                .off {
                    visibility: hidden;
                } .on {
                    visibility: visible;
                }
            </style>
            <script type="text/javascript">
                window.onload = function() {
                    var timeInterval = 5; //Delay of showing the submit buttons in seconds. Set the delay that you want to use in your case.
                    if (typeof timeInterval === 'undefined' || parseInt(timeInterval) <= 0) {
                        timeInterval = 1
                    }
                    document.getElementById('timeinfo').innerHTML = timeInterval + " Seconds more to load the submit button";
                    var si = setInterval(function() {
                        if (timeInterval === 0) {
                            clearInterval(si);
                        } else {
                            --timeInterval;
                            if (timeInterval !== 0) {
                                document.getElementById('timeinfo').innerHTML = timeInterval + " Seconds more to load the submit button";
                            } else {
                                document.getElementById('timeinfo').className = 'off'; //Hiding the counter area.
                            }
                        }
                    }, 1000);
                    setTimeout(function() {
                        document.getElementById('submit').className = 'on';
                    }, timeInterval * 1000);
                }
            </script>
        </head>
        <body>
            <div id="timeinfo">
            </div>
            <br/>
            <form name="f" action="" method="get">
                <label>
                    Name 
                </label>
                <input type="text" name="fname" id="fname" />
                <br/>
                <input type="submit" name="submit" id="submit" value="submit" class="off"/>
            </form>
        </body>
    </html>
    Hope this helps.
    Last edited by codeexploiter; 02-18-2009 at 10:09 AM. Reason: code formatting

  9. The Following User Says Thank You to codeexploiter For This Useful Post:

    nicksalad (02-18-2009)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •