1
Hello, In php there is some way to make the button below call the function turns off()
$button2 = "<input type='button' id='php_button' value='desliga' onclick='desliga()'>";
echo $button;
when clicking the button appears the error: Uncaught Referenceerror: turns off is not defined onclick
I’ll explain better what I need.
I need to create some buttons dynamically because the number of buttons can change. For example I might need 5 buttons with different names that call the same function.
using only html as described below works, but this way I can not create the buttons dynamically. As described below the code works, but what I want is to be able to create as many buttons as I want according to the result of num_rows of a query sql.
<?PHP
function liga(){
echo "teste";
}
<input type="submit" name="liga" value="liga"/>
if (isset($_REQUEST['liga'])) {
unset($_REQUEST['liga']);
liga();
?>
It’s impossible to do what you want the way you’re shown. If you have other pieces of code that help clarify what you are trying to do, you may have another solution. But in general it seems impossible. PHP and JS are different languages and completely independent.
– Maniero
I tried to explain better see if you can help me
– Roberto Bahia
Improved. Where is this function
liga()
? Is it written in JS or PHP? If it is in JS, I already know that it is not possible to do this. As I said, languages are independent, despite the popular belief that they work together. It is not easy to respond with partial codes. It does not mean that you need to put everything you have but something minimal that can produce a useful result. http://answall.com/help/mcve– Maniero
right, I put an example of function
– Roberto Bahia
I still can’t figure out what you want. Aside from a few organizational errors and syntax what you are demonstrating works but I doubt it will do what you want. If you can’t demonstrate what you want to do, I won’t be able to answer. I hope someone else can, but it’s probably the best guess. See how http://ideone.com/bRPhwd. Let me repeat: if you think PHP and JS are the same language, that you can write everything mixed up and it will work, forget it. If you want a solution to the problem, consistently describe the real problem.
– Maniero
is the typical error of beginners in mixing server side and client side.. I think a better way is to guide Roberto to understand server-side and client-side, browser, servers, etc.
– Daniel Omine