Click to See Complete Forum and Search --> : Disabling Submit Button
l0tt0
01-31-2004, 08:21 PM
Can anyone tell me how to disable a submit button once it is clicked. I want to use it to stop double posting.
I have no javascript experience...but intend on learning...
so any help would be appreciated.
thanks in advance
fredmv
01-31-2004, 08:30 PM
Welcome to the forums.<input type="submit" value="Submit" onclick="disabled=true;return true;" />
l0tt0
01-31-2004, 08:40 PM
thanks for the welcome, Glad to be here :)
for the code i tried it and when i click it, it disabled
like it is supposed to...
but doesnt load up the next page
i have no clue, any ideas?
buntine
01-31-2004, 08:53 PM
try removing the 'return true;' statement.
Normally, return true would send the form. So this is a bit odd.
fredmv
01-31-2004, 09:07 PM
Originally posted by buntine
try removing the 'return true;' statement.No. That should remain there because otherwise the form would not submit. The form must recieve a Boolean value of true in order to submit. Otherwise, the button would be disabled and the form wouldn't submit.Originally posted by buntine
Normally, return true would send the form. So this is a bit odd. No kidding. As mentioned before, we want this to happen so the button will be disabled and then the form will submit.
l0tt0
01-31-2004, 09:11 PM
So...any other ideas? :P
I also didn't mention that I Code In PHP, so maybe there's something wrong because I had to cancel out the quotes? Here's What I put...
<input type=\"submit\" value=\"Submit\" name=\"submit\" onclick=\"disabled=true;return true;\" />
fredmv
01-31-2004, 09:18 PM
Try using an onsubmit event handler instead:<script type="text/javascript">
//<![CDATA[
function disableSubmit()
{
document.forms[0]['submit'].disabled = true;
return true;
}
//]]>
</script><form action="#" onsubmit="return disableSubmit();">
<div>
<input type="submit" value="Submit" name="submit" />
</div>
</form>
l0tt0
01-31-2004, 09:29 PM
I put the script code in the header...is that correct?
and i put that other thing and changed the # to the place i want it to go
but when i click submit i cant see it going down...
heres where im clicking it
http://24.103.133.150/
user: 9mm
pass: 9mm
can some1 try it and tell me if it works...
i have cable internet...so i dont kno even when i click stop it dont appear to be dwon
buntine
01-31-2004, 09:57 PM
Actually, javascript doesnt need to return a value unless you tell it to. Demonstrated below:
<html>
<head>
<title>...</title>
<script language="javaScript">
<!--
function disable_button() {
document.getElementsByName("sub")[0].disabled = true;
}
-->
</script>
</head>
<body>
<form method="post" action="none.html" name="my_form" onsubmit="disable_button();">
<input type="submit" name="sub" value="click me" />
</form>
</body>
</html>
Regards.
fredmv
01-31-2004, 10:08 PM
Originally posted by buntine
Actually, javascript doesnt need to return a value unless you tell it to. It is a good practice when dealing with forms to return either a true or false Boolean value when validating forms based on if it should submit or not.
buntine
01-31-2004, 10:11 PM
Oh yes, i agree with you.
I was just showing you that the form does not need a boolean value in order to perform an action before it is sent to th server for processing. ;)