1

Please help me to fix this code :(

echo'<td style=" width: 20%"><input type="button" value="inactive" onclick="set_user_inactive($user_id)">   
        </td>';

I need function set_user_inactive($user_id) works if user click on the button in the table.

I won't use form I need it v.simple

html and php

Thanks

NamshanNet
  • 426
  • 1
  • 6
  • 20
  • http://stackoverflow.com/questions/1207939/adding-an-onclick-event-to-a-table-row – Ed Capetti Feb 08 '14 at 11:22
  • 2
    Wait, is `set_user_inactive()` a php function? In this universe, you cannot run PHP from the client side. You'll need a lot more than a simple onclick call to run a PHP function, ajax is your best bet. See: http://stackoverflow.com/questions/7165395/call-php-function-from-javascript – Christian Feb 08 '14 at 11:29

2 Answers2

1

The short answer is no you cant do this. Php is run on page load and cannot be interacted with via the dom.

A slightly longer answer would be to set up a service page to handle your php which you can run from the from end.

Create a single php call it something like setInactive.php and do something like the following

<?php
set_user_inactive($_POST["user_id"])
?>

Then use javascript or jquery to post to that page.

function set_user_inactive(val){
 $.post( "setInactive.php", { user_id: val} );
}

Thats a rough starting point hope it helps

Dominic Green
  • 9,716
  • 4
  • 27
  • 34
0

Here you go , this will call JavaScript function

        $user_id    = 1; 

        $onclick    =   "onclick=set_user_inactive($user_id);";


        echo    '<td style=" width: 20%">

                   <input type="button" value="inactive" '."onclick=set_user_inactive($user_id)".'>   

                </td>';
Dimag Kharab
  • 4,218
  • 1
  • 18
  • 41