SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast Damage's Avatar
    Join Date
    Apr 2001
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Is this possible??? Never seen it done before..

    I have a submit button on a form that I'd like people to NOT press more than once since the backend of our server takes a while to process the form sometimes. People tend to click on the button 2X or more. Is there a way to have it so a popup window pops up and tells them not to click on it more than once? I'd like to have it say something like, "Slow the hell down buddy! There's no need to click on this twice."

    Thanks for the help in advanced.

  2. #2
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yeah, there is a way to make that happen:

    <input type="submit" onClick="window.open()">

    You can replace the window.open() with the tailored command here: http://www.studiococo.com/custom.asp?window.asp

    There is also a way to make the form button not be pressed twice, let me see if I can find it

    here it is

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    function submitonce(theform) 
    {
    	if (document.all || document.getElementById) 
    	{
    		// hunt down "submit" and "reset"
    		for (i=0;i<theform.length;i++) 
    		{
    			var tempobj=theform.elements[i];
    			if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset") 
    			{
    				tempobj.disabled=true;
    			}
    		}
    	}
    }
    // End -->
    </script>
    The above code will disable the clicking of the Submit and the Reset button after the form has been submitted.

    You'd call it like this:

    Code:
     <form action="/submit.php" name="submission" method="post" enctype="multipart/form-data" onSubmit="submitonce(this);">
    Hope that helps!
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  3. #3
    SitePoint Enthusiast Damage's Avatar
    Join Date
    Apr 2001
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Close...

    That code seems to disable the submit button. I want it still enabled, but if they hit it once, and try a second time while the server is still processing the form, I'd like a popup window to come up and tell them to be patient. Possible?


    Originally posted by Jeremy W.
    Yeah, there is a way to make that happen:

    <input type="submit" onClick="window.open()">

    You can replace the window.open() with the tailored command here: http://www.studiococo.com/custom.asp?window.asp

    There is also a way to make the form button not be pressed twice, let me see if I can find it

    here it is

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    function submitonce(theform) 
    {
    	if (document.all || document.getElementById) 
    	{
    		// hunt down "submit" and "reset"
    		for (i=0;i<theform.length;i++) 
    		{
    			var tempobj=theform.elements[i];
    			if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset") 
    			{
    				tempobj.disabled=true;
    			}
    		}
    	}
    }
    // End -->
    </script>
    The above code will disable the clicking of the Submit and the Reset button after the form has been submitted.

    You'd call it like this:

    Code:
     <form action="/submit.php" name="submission" method="post" enctype="multipart/form-data" onSubmit="submitonce(this);">
    Hope that helps!
    Last edited by Damage; Jan 31, 2002 at 18:27.

  4. #4
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    how about something like this?

    <....onSubmit="return someFunc()"...>


    function someFunc()
    {
    if (! window.alreadyClicked)
    {
    alreadyClicked = true;
    ...whatever validation you do...
    return true;
    }
    return false;
    }

    The above should allow only one click per page session.

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still


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
  •