how to make an if with php parameters inside javascript

Asked

Viewed 53 times

-1

I need to do a check before changing html elements, I tried this way but it did not work does not enter if in any circumstances.

    <script>
    if("<?php empty($usuario_pesquisado->getArea()->getNome()) ?>")
    {
        $('#area_item').css("opacity", 0.4);
    }
    if("<?php  empty($usuario_pesquisado->getFormacao()) ?>")
    {
        $('#formacao_item').css("opacity", 0.4);
    }
   </script>
  • Use the condition in PHP, if the result is true, you print the JS code with the echo. If your PHP is version 7+, use <?php echo (!empty($usuario_pesquisado->getArea()->getNome())) ?: '$('#area_item').css("opacity", 0.4);' ?>

  • Yes php use 7, unfortunately it didn’t work :/

  • uses the if. Basis: http://codepad.org/Bc75rDMf

  • vlw friend, now it worked :D

1 answer

0

Dude, I would do a request with AJAX taking the values from the PHP page:

$.get( "ajax/test.html", function( data ) {
  $( ".result" ).html( data );
  alert( "Load was performed." );
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.