Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to pass variables and data from PHP to JavaScript ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 183
    Comment on it

    Welcome to findnerd, today we are going to discuss How to pass variables and data from PHP to JavaScript.
    In this blog we demonstrate and describe passing PHP variables containing simple data types to JavaScript.

    There are actually several approaches to do this.There are some conditions when pass variables
    and data from PHP to JavaScript that data and variable always encode with json_encode otherwise error may be generate. So the PHP json_encode function can be used to resolve these problems.

    Yoa can take reference of bellow example:

    There is a php code in tn which two varibale are avaiable
    <?php
    //here ctrate a variable name is $sum 
    $sum = 10 + 5;
    //here ctrate a variable name is $Name 
    $Name = "Jorden";
    ?>
    
    <script type="text/javascript">
    //here write a javascript variable and pass php variable
    var sumdata=<?php echo json&#95;encode($sum); ?>; //write here the extra semicolon!
    
    //here write a javascript variable and pass php variable
    var Getname=<?php echo json&#95;encode($sum); ?>;//write here the extra semicolon!
    
    </script>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: