Diabling submit buttons

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
k_nitin2k
Forum Newbie
Posts: 5
Joined: Sun Mar 30, 2003 1:17 pm

Diabling submit buttons

Post by k_nitin2k »

Hi,
i am a newbie in PHP. Is there any way in PHP to disable submit buttons after clicking it once or atleast disable them for a while(5-10) secs.
Thanks...
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

eh?...
hedge
Forum Contributor
Posts: 234
Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada

Post by hedge »

You have to do it with javascript.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

<html>
	<head>
		<script type="text/javascript">
			function toggleButton(sId)
			&#123;
				o = document.getElementById(sId);
				if (o != null)
				&#123;
					if (o.disabled)
						o.disabled = false;
					else
						o.disabled = true;
				&#125;
			&#125;
			
		</script>
	</head>
	<body>
		<form method="POST" onSubmit="toggleButton('s1'); return false;" >
			<input type="submit" id="s1" disabled="disabled" />
			<script type="text/javascript">
				setTimeout("toggleButton('s1')", 5000);
			</script>
		</form>
	</body>
</html>
actual posting is suppressed.
Without javascript (or disabled) users cannot post at all :-S
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Or... Do it the way I do it. ;)

Code: Select all

<SCRIPT LANGUAGE=javascript>
<!--
var submitDone;
submitDone = 0;
	function preventDoublePosts() &#123;
		if (document.all && document.frmMain.cmdSubmit) 
&#123;
	document.frmMain.cmdSubmit.disabled = true;
	document.frmMain.cmdSubmit.value = 'Saving File...';
		&#125;
		if (submitDone == 0) &#123;
			submitDone = 1;
			return true;
		&#125;
		else &#123; 
			if (!document.frmMain.cmdSubmit || !document.all) &#123;
			alert("Saving File..."); 
			&#125;
			return false; 
		&#125;
	&#125;
//-->
</SCRIPT>
Then, example of use:

Code: Select all

<form action=example.php method=POST id="frmMain" name="frmMain" onSubmit="return preventDoublePosts();">
<input type=submit value="  Save Now  " id="cmdSubmit" name="cmdSubmit"></form>
Image Image
k_nitin2k
Forum Newbie
Posts: 5
Joined: Sun Mar 30, 2003 1:17 pm

Post by k_nitin2k »

Code: Select all

<?
echo"<SCRIPT LANGUAGE=javascript> 
<!-- 
function torf(a) 
&#123;
  if (a.element) &#123;
    return false;
  &#125;
  else &#123;
    return (a.element = true);
  &#125;
&#125;</SCRIPT>";

?>

<SCRIPT LANGUAGE= "javascript"> 
<!-- 
function wform(a) &#123;
  document.write('<form onSubmit= "return torf(this); " method="post" action=" '+a+' ">\n');
&#125;</SCRIPT>";

<SCRIPT LANGUAGE= "javascript"> 
<!--
function wsubmit(a) &#123;
  document.write('<input type="submit" name= "Submit" value= " '+a+' " class= "submit">\n');
&#125;
</SCRIPT>";

<script language="JavaScript">
wform( "test.php?usrid=<? echo $usernumber; ?>&rulername=<? echo $rulername; ?>&galaxypos=<? echo $galaxypos; ?>&systempos=<? echo $systempos; ?>&gamemode=<? echo $gamemode; ?>");
</script>

<script language="JavaScript">
wsubmit("Send Out Attack");
</script>
Post Reply