Forum Moderators: phranque

Message Too Old, No Replies

Allowing people to click a button only once?

So we don't get double credit card payments for one order...

         

PFOnline

3:47 am on Mar 28, 2003 (gmt 0)

10+ Year Member



Anyone know how to do it?

toadhall

4:10 am on Mar 28, 2003 (gmt 0)

10+ Year Member



You could hack this:

<input type="Button" name="Submit" value="Submit Form" onClick="if(this.value == 'Submit Form') this.form.submit(); this.value = 'Please Wait...';">

T

PFOnline

4:19 am on Mar 28, 2003 (gmt 0)

10+ Year Member



toadhall, thanks :) I tried that, and it's interesting, but it still has the possibility to submit more than once...

I'm looking for a certain kind of button, (I've seen it before so I know it exists... somewhere!) that just doesn't allow you to click more than once, so it would make it impossible to get double orders/cc payments...

But, thats an nice bit of code, thanks... :)

toadhall

5:03 am on Mar 28, 2003 (gmt 0)

10+ Year Member



It won't let a second submission take place. The conditional checks the form value and will submit only if the value is 'Submit Form', then changes the form value to 'Please Wait...', which prevents a second submission as the value no longer meets the condition.

T

PRNightmare

5:06 am on Mar 28, 2003 (gmt 0)

10+ Year Member



Before you try this one, try toadhall's suggestion. It looks clean to me.

Here's something I found that does the trick. Requires modification.

<!-- This goes in the head -->

<SCRIPT LANGUAGE="JavaScript">

var submitcount=0;

function reset() {
document.yourform.formdata1.value="";
document.yourform.formdata2.value="";
document.yourform.formdata3.value="";
}

function checkFields() {
if ( (document.yourform.formdata1.value=="") ¦¦ (document.yourform.formdata2.value=="") ¦¦ (document.yourform.formdata3.value=="") )
{
alert("Error: Your didn't fill out the form.");
return false;
}

else
{
if (submitcount == 0)
{
submitcount++;
return true;
}
else
{
alert("This form has already been submitted.");
return false;
}
}
}
// End -->
</script>

<!-- Make sure you do the onLoad handler in the body tag -->

<BODY OnLoad="reset()">

<!-- Here's the form itself -->

<form method=post action="responsepage.asp" name="yourform" onSubmit="return checkFields()">

<input type=text name="formdata1">
<input type=text name="formdata2">
<input type=text name="formdata3">

<input type=submit value="Submit Form">

</form>

Visit Thailand

7:29 am on Mar 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Toadhall that's pretty handy. Can I ask will that work in all browsers?

toadhall

4:56 pm on Mar 28, 2003 (gmt 0)

10+ Year Member



> work in all browsers?

All browsers that support Javascript 1.2 and up.

<edit>correction in Javascript version</edit>

Visit Thailand

2:02 am on Mar 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks toadhall. That is what I thought. So am I right in saying that if a browser has javascript disabled it would not work? What would happen is they have java disabled would the form still be submitted?

toadhall

2:17 am on Mar 29, 2003 (gmt 0)

10+ Year Member



That's right. As DrDoc has pointed out in the duplicate post ( [webmasterworld.com...] ), it's client-side and not goof proof given the variety of browsers, versions, and (especially) user configurations. So back it up server-side.

T