submit button grayed out to stop submitted twice

When a user submits direct payments from my website to paypal some times it can take a few seconds to process before it proceeds to the confirmation page.

Does anyone solutions to do the following...

1) A pop up message say your order is being processed till the page redirects to the confirmation page.

2) Gray out the submit button / image so the user will not be able to click the button again if they are being impatient?

I would also be interested in other suggestions? Thanks
petewinterAsked:
Who is Participating?
 
sandeshjConnect With a Mentor Commented:
In javascript you could put a code something like this...

onclick="this.style.cursor = 'wait'; this.disabled=true;  this.form.submit()"

Open in new window

0
 
sandeshjConnect With a Mentor Commented:
Sorry should have described what happens above.
I've re pasted the complete code for the image button.

On click the mouse cursor changes to waiting icon,
The button will be disabled.
The pressed button will stay as it is, it wouldn't go back to the release(original) icon...
<input name="someting" type="image" src="ProperButtonImage.gif" alt="Click to place order" value="SomeValue" onclick="this.style.cursor = 'wait'; this.disabled=true;  this.form.submit()"
                  onmouseover="this.src='OnClickButtonImage.gif'"
onmouseout="this.src='ProperButtonImage.gif'">

Open in new window

0
 
StealthyDevConnect With a Mentor Commented:
Hi,

You should use a Synchronous AJAX call for this.

As soon as you get the control to your function (before calling AJAX page), disable the button using the code by sandeshj (above post).
After you get the response, set the button to enabled (if required, or move to next action, hopefully, message box saying failure/success).

Regards
buttonObject.disabled=true;
//place ajax call here

//after you get the response
buttonObject.disabled=false; // if required

Open in new window

0
 
StealthyDevConnect With a Mentor Commented:
Hi again,

Since you have asked for other interesting suggesion, i would talk about JQuery. (Interesting, isn't it?)

Please find the below code, which is much easier to work with AJAX.

P.S:
You can download JQuery from:
http://jquery.com/


<script type="text/javascript" src="jquery-1.4.2.min.js"></script>

<input type=button onclick="pay()" id="btn" value="pay">

<script>

	function pay()
	{
		$("#btn").attr("disabled", true);
		$.post('myajax.html', '123', function(ress){
			alert(ress); // ress is the result from the ajax page
		});
	$("#btn").attr("disabled", false);
	$("#btn").attr("value", "pay again :)");
	}

</script>

Open in new window

0
 
petewinterAuthor Commented:
Many Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.