[Solved] How to add PHP on Javascript code [closed]


It’s certainly possible to output JavaScript with PHP, much like you can output HTML. It’s really no different. Let’s say your PHP has the value you want to output stored in $number:

<input type="button" class="btn_<?php echo $number; ?>" value="Tafsir Jalalain"/>


<script>
$('document').ready(function(){
    $(".btn_<?php echo $number; ?>").click(function(){
        $(".field<?php echo $number; ?>").toggle();  
    }); 
});
</script>

Your output HTML and JavaScript will now all use the value from $number, whatever that is. Please note – this will output a $number into your page, ONCE. The value injected into your page will not change once the page is loaded. If you need to dynamically change the content of the HTML without reloading the page, you’ll need to look into AJAX.

8

solved How to add PHP on Javascript code [closed]