How to inject javascript code that uses php variables into php page

Assign PHP variable’s value to java script variable :

<script type="text/javascript">
    var json{
    "id":<?php echo $id;?>,
    "user" : "<?php echo $user;?>"

Change this line from your code :

 $.post('full.php', {msgg: msg, from:, to: json.user}

Now you’ll have separate js file like:

      function send(e){
        if(e.keyCode == 13 && !e.shiftKey){

//Get the input data using the post method when Push into mysql is clicked .. we pull it using the id fields of ID, Name and Email respectively...

//Get values of the input fields and store it into the variables.
var msg=$("#reply").val();
//here you start PHP->>
//here we put the PHP Variables ^^^^^^^^^///\\\

//use the $.post() method to call insert.php file.. this is the ajax request
$.post('full.php', {msgg: msg, from:, to: json.user},
function clear() {
$("#myre :input").each(  function() {
    $(this) .val('');


Say this file is myjs.js now include it in php file:

<script type="text/javascript" src="" />

Browse More Popular Posts

Leave a Comment