PDA

View Full Version : How to Disable submit button



poyor7
05-11-2006, 05:48 AM
Hi,

I've a test.php page with submit button and the process/display also in the same page(test.php).So,my question is how to disable submit button after submission test.php.I mean submit button in the test.php disable after the submission not during the submission....any idea???

Regards
Khairul

djr33
05-11-2006, 06:01 AM
Please post a link to the page on your site that contains the problem so we can check it out.


The "process/display" is?



after the submission not during the submission
huh?


I think you're asking how to disable sending the form twice.... making sure they don't just keep clicking submit.

I'm not sure how this would work.

but, since you're using php, you could just have a check before doing your action.

1. Store the submissions somewhere (or even just the one last one)
2. Check when submitted if that data matches the old data (and IP address)
3. If it does, end, do nothing (already submitted... no big deal), if not do your normal action.


I'm not sure what "disable" is in javascript, but you could do it this way:
either onSubmit in the <form> tag, or onClick on the submit button....

You could set that to a function.

the function could set a variable to 1 and submit the form.
The fuction, when clicked again, would see that it already equals 1, and not do anything.
if != 1, var = 1, submit. else (do nothing, probably or alert('only submit once.'))

poyor7
05-11-2006, 06:32 AM
Hi....
Thanks for the reply...
Anyway...process and display is in the same page that is test.php.to be clear...from test.php --->submit--->process-->display--->test.php...so all is one page.
so i wondering if there is javascript that can disable the submit button after the submission i mean at the test.php for display part

Regards
Khairul

djr33
05-11-2006, 06:37 AM
Ok.

So... is the "process/display" php or javascript based?

You could submit the page to itself, have php run through the $_GET or POST variables, then do stuff.
Or you could have a javascript action attached to submit that does stuff with the values in the form.

Either way, I still say make an onSubmit="function()", where function() checks if var == 1. If not, it makes it equal 1, and does your action. If it DOES equal 1, then it does nothing. This is basically turning on a switch the first time it's submitted then not allowing it again.
There MAY also be a disable function for a button. I don't know about this. Try googling it. But, make it work would be easy... just onClick="thatfunction" Or, maybe onSubmit for the form tag.


And, again, I can't picture it.... Please link to your page!

poyor7
05-11-2006, 07:12 AM
Hi...

Sorry i couldnt post the link since is just using localhost....anyway the page of-course in php but i wanted to use javascript for disabling the submit button...yes i did googling about this problem....but the most of the solution are disable for multiple click/submission..mean the button disable during the submission/loading and the page submiited is not the same is different page....which is not what i want....

Regards,
Poyor7

Twey
05-11-2006, 07:14 AM
document.forms['nameOfForm'].elements['nameOfSubmitButton'].disabled = true;

poyor7
05-11-2006, 07:24 AM
Hi..
Twey...

Then in the html code what changes should i make?

Regards
Poyor7

poyor7
05-11-2006, 07:43 AM
Hi...

Here i try to use Twey idea...it only disable button but not submitting at all..
-------
function SubmitTheForm()
{
document.forms['form'].elements['Submit'].disabled = true;
}
-------
test.html page
<form name="form" action="test.html">
<input type="submit" name="Submit" value="Save" onclick="return SubmitTheForm();">
<form>

Regards,
Poyor7

poyor7
05-11-2006, 08:13 AM
Hi...

Based on this script....where how where should i put coding for disable button?example like twey coding....

<SCRIPT LANGUAGE="JavaScript">

function SubmitTheForm()
{
if (input.validation.value=="false")
{
input.validation.value="true";
}
else
return false;
}
}
</SCRIPT>
<FORM name="form" action="test.html">
<input type="submit" name="Submit" value="Save" onclick="return SubmitTheForm();">
<input type="hidden" name="validation" value="false">
</FORM>

Regards,
Poyor7

Twey
05-11-2006, 11:46 AM
<form action="test.html" onsubmit="
if(!this.form.elements['validation'].value) return (this.form.elements['validation'].value = true);
else return !(this.form.elements['Submit'].disabled = true);
">
<input type="submit" name="Submit" value="Save">
<input type="hidden" name="validation" value="">
</form>I think that's right, but I'm not entirely sure what you're trying to do here.