3
You can run these PHP functions via HTML?
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8"/>
<meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">
<title>Dispara condição no PHP</title>
<link href="css/seu-stylesheet.css" rel="stylesheet"/>
<script src="scripts/seu-script.js">
// Função que dispara a if(isset($_POST['LP1'])){ if($msg[0]=='1') { $msg[0]='0'; } else { $msg[0]='1'; }} no php
function executaLP1()
{ }
// Função que dispara a if(isset($_POST['LP2'])){ if($msg[0]=='1') { $msg[0]='0'; } else { $msg[0]='1'; }} no php
function executaLP2()
{ }
</script>
</head>
<body>
<!--Botões que produzem o mesmo efeito daqueles do PHP-->
<input type="button" value="OK" onclick="executaLP1"/>
<input type="button" value="OK" onclick="executaLP2"/>
</body>
</html>
PHP:
<?php
//Tenho esse código em php
if(isset($_POST['dado'])) {
$msg = $_POST['dado'];
if(isset($_POST['LP1'])){ if($msg[0]=='1') { $msg[0]='0'; } else { $msg[0]='1'; }}
if(isset($_POST['LP2'])){ if($msg[1]=='1') { $msg[1]='0'; } else { $msg[1]='1'; }}
//Com esses 02 botões abaixo
//Ao clicar no primeiro botão, executamos a condição LP1 e ao clicar no outro, executamos a condição LP2.
echo "<button style=\"width:966; height:150; color:#FF8040; background-color: $cor1 ;font: bold 50px Arial\" type = \"Submit\" Name = \"LP1\">Botão 01</button></br></br>";
echo "<button style=\"width:966; height:150; color:#FF8040; background-color: $cor2 ;font: bold 50px Arial\" type = \"Submit\" Name = \"LP2\">Botão 02</button></br></br>";
// Minha dúvida é a seguinte:
// Tem como executar essas mesmas condições só que com botões em HTML com auxílio do JS ou jQuery?
// Acima, fiz o código em HTML só para compreensão das ideias. Se houver como fazer isso sem a página atualizar, seria excelente!
?>
I posted the code fragment on github for clarity!
My question is this: You can execute these same conditions only with HTML buttons with the help of JS or jQuery?
Above, I made the code in HTML just to understand the ideas. If there is how to do this without the page update, it would be great!
Hello Jurandir, welcome to SOPT. Just a tip, but it’s always best to post the code right here. I edited for you (this is normal here), see how good it was. : ) Just paste the code, select everything and give a Ctrl K. Hug. In time: also includes the text of the question out of code to make it easier to find the problem.
– gustavox
About the question, I do not know if I understand well, but to do without updating the page you can use ajax.
– gustavox
I don’t believe I’m a duplicate. In the link referenced by @Guilhermelautert the user wanted to run php in javascript, here he wants to "know" if there is a compatible way in javascript or html to run a php equivalent. Good in html not even! I think it is clear if it is a dynamic load
– Lauro Moraes
gsutavovox, grateful for his guidance and insight!
– Jurandir Hora
Lauro Moraes, grateful for the exact interpretation of my question!
– Jurandir Hora