PDA

View Full Version : javascript for single click button



Jamal
11-06-2006, 10:04 AM
hi every one :)


i need a javasript that will allow user to click on the button once, after it it may disable the button.


please help.

thanks

codeexploiter
11-06-2006, 10:10 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form>
<input name="Button" type="button" onClick="this.disabled = 'true';" value="Press Me">
</form>
</body>
</html>

Jamal
11-07-2006, 07:02 AM
thanks budd

well i tried to disabled the submit button through onclick but i prevents my form from submition instead i worked this way and have made it :)

<SCRIPT LANGUAGE="JavaScript">
var submitcount=0;

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


and...

<html:form action="/someAction" onsubmit="return checkFields()">

mwinter
11-07-2006, 09:03 PM
<input ... onClick="this.disabled = 'true';" ...>

Changing the attribute value to:

&#160;&#160;this.disabled = 'false';

would still disable the control. :)




well i tried to disabled the submit button ...

Don't. If the submission fails and the user needs to resubmit, the button may still be disabled when they use the Back button to return (this behaviour varies between browsers, but does occur).

If multiple submissions breaks your server-side code, then that code is broken itself. Detect and deal with it properly on the server.

Mike

tech_support
11-07-2006, 09:46 PM
Or you could use DD's scripts: http://www.dynamicdrive.com/dynamicindex16/disableenter.htm