Friday, June 19, 2009

prevent multiple form submit at client side

In Html tag Button one issue is that they can be clicked more than once, and under certain circumstances this can cause issues. because of that may be data may get inserted multiple time, wrong information can be get added and so on. To ensure that the button can only be pressed once you can do the following.

Actually there may way to do this
1. Disable button

javascript:this.disabled=true;this.value='Submitting....';doSubmit('SUBMIT');

Simply add this in you button onClick method

<INPUT TYPE="Button" VALUE="Submit" onClick="if(this.value == 'Submit') this.form.submit(); this.value = 'Please Wait.';this.disabled=true;">

2. Count click

Second one is count how many times user get click on it


<script language="javascript">
var NoOfClick=0;
function chksubmit()
{
if NoOfClick >0)
{
alert("Wait! Request is in Process...");
return false;
}
NoOfClick ++;
document.creditcardinfo.action="xyz.asp";
document.creditcardinfo.submit();
}

<html>
<itle> button Ex <title>
<body> <form>
<input type="button" value="Submit" onClick="chksubmit();">
</form></body>
</html>


3. Hide button

in this section simply define one Div and in javascript hide or show that div section , so when user click on submit that div(consider loding images) will appear on Submit button and user will not able to view that submit button.like that way also you can stop user to clicking more than ones time.

hope you like my tricks
any query plz let me know?

1 comment: