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

2

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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>';

4 Comments

You're not using $onclick after definition at all, what's the point?
@CodingAnt why $onclick ?
As per my understanding , set_user_function is a JavaScript function @Robuust .
$onclick separate beacause I m not able to save my answer here so only a workaround :P @NamshanNet

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.