Click here to Skip to main content
15,347,625 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
<td><a class="edit" title="Accept" href="javascript:void()" onclick="get_accept('<?php echo $data['id'];?>');" >Accept</a></td>



how can i disable or disappear from the page this Accept button after first click because i am sending a timestamp value from this button and when a user click this button after some time then it will get new timestamp.
please help.
Posted
Updated 24-Jul-12 12:45pm
v4
Comments
Sergey Alexandrovich Kryukov 23-Jul-12 20:05pm
   
How's that? :-)
--SA

As Sergey mentions, you can't do it 'directly' from php. But you can output the appropriate javascript that will do so.

I don't construct pages in php using string concatenation, preferring the DOM methods myself. But in any case, you can achieve the task with the following:

HTML
<td>
  <button onclick="get_accept('<?php echo $data['id'];?>'); this.disabled='disabled';">Accept</button>
</td>


You can see it in action with the simplest of pages:
HTML
<html>
  <head>
  </head>
  <body>
    <button onclick="this.disabled='disabled';">Disable Me</button>
  </body>
</html>



Here's a page that demonstrates it further:

PHP
<?php
	$myButtonText = "click me if you can!";
?>

<!DOCTYPE html>
<html>
  <head>
  <script>
	function get_accept(input)
	{
		alert(input);
	}
	function changeText(el)
	{
		el.innerHTML = '<?php echo $myButtonText;?>';
	}
  </script>
  </head>
  <body>
    <button onclick="changeText(this); get_accept('<?php echo $myButtonText;?>'); this.disabled='disabled';">Disable Me</button>
  </body>
</html>
   
v3
Comments
ambujmalviya 24-Jul-12 13:17pm
   
thanks for help but it is not working. i tried earlier this.disabled='disabled' but it is not working on my page,and second example that you given it working only untill we dont refresh the page when we refresh the page then it will clickable.
enhzflep 24-Jul-12 13:40pm
   
Yes, it is working - just fine over here in fact.
Please see my edited solution above.

It will disable the button and change it's text using php variables.
'this' is sensitive to scope - you can use it in an event handler, but not in a function called from an event handler. Hence the passing of the 'this' param in my newer code.
Sergey Alexandrovich Kryukov 27-Jul-12 17:56pm
   
My 5 for the answer. Looking at OP's reply to both your and my answers, she/he cannot get it; I don't know what else to say...
--SA
There is no such thing as "click in PHP". :-)
And you cannot "disable a button" in PHP. PHP is server side, it only generates the HTML page, and only with JavaScript you can disable or enable elements.

What's the problem? For example, see this article with samples:
http://www.codetoad.com/javascript/enable_disable_form_element.asp[^].

See also:
http://www.w3schools.com/tags/att_input_disabled.asp[^].

—SA
   
Comments
ambujmalviya 24-Jul-12 12:25pm
   
thanks for suggestion but it is not the solution of my problem.
Sergey Alexandrovich Kryukov 27-Jul-12 17:55pm
   
This is only because you did not clearly realized your problem.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900