Convert PHP function to JavaScript

-1

I'm not very knowledgeable about JavaScript. I need to convert this check below that is in PHP to JavaScript.

How can I do this?

$verificao = $_POST['verificacao_name']; 
$pesquisa1 = $_POST['p1']; 
$pesquisa2 = $_POST['p2'];

if (($verificacao == 2) and
   (($pesquisa1 <= 8 and $pesquisa1 != 0) or  
    ($pesquisa2 <= 8 and $pesquisa2 != 0) or  
    ($pesquisa3 <= 8 and $pesquisa3 != 0))) {
       echo 'Erro'; 
else{
       echo 'Ok'; 
}
    
asked by anonymous 10.08.2016 / 18:39

1 answer

2

Given the incomplete information, I assume that you want to check values filled in inputs , below follows one and is almost identical to PHP :

function verificar() {
  var verificacao = parseInt(document.getElementsByName("verificacao_name")[0].value);
  var pesquisa1 = parseInt(document.getElementsByName("p1")[0].value);
  var pesquisa2 = parseInt(document.getElementsByName("p2")[0].value);
  var pesquisa3 = parseInt(document.getElementsByName("p3")[0].value);

  if (
    (verificacao == 2) && (
      (pesquisa1 <= 8 && pesquisa1 != 0) ||
      (pesquisa2 <= 8 && pesquisa2 != 0) ||
      (pesquisa3 <= 8 && pesquisa3 != 0)
    )
  ) {
    console.log("Ok");
  } else {
    console.log("Erro");
  }
}
<input type="text" name="verificacao_name" />
<input type="text" name="p1" />
<input type="text" name="p2" />
<input type="text" name="p3" />

<input type="button" value="Verificar" onClick="javascript:verificar();">
    
10.08.2016 / 19:10