There is a javascript code with a variable that contains the result, depending on it I want to output a part of the code (HTML + PHP). Thinking, I came to the conclusion that you need to somehow transfer the variable from js to php, which would then make the if else conditions in PHP and output what you need. Since it is more convenient to do this with PHP, for example, you can do so

<? if(1=1) { ?> Сдесь любой код <? } ?> 

On js, I have not yet figured out how to do this. I think it is possible to do this using Ajax, but if there is any other simpler and more suitable way, I will be glad to know.

  • ajax what we need, drank rest requests and that's all - Jean-Claude

1 answer 1

I sometimes do this:

 JS: var count = <?php echo $param; ?> if (count > 2) { alert(count); } else { *some_code* } 

I don’t know how high the level of kostichnosti is here, but with simple tasks it is easier than AJAX to load data


Sorry, misunderstood the question