import php variable to javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • loveyl
    New Member
    • Apr 2012
    • 1

    import php variable to javascript

    hi all

    i am new to web programming and m stuck at one point. i want to import a php variable to javascript and later want to display it in a text box which should be triggered by "onclick" event by a submit button..plsss help!!
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    this is the most simple problem;
    here is an example solution;

    Code:
    <?php
    $to_disp="excel";
    ?>
    <script>
    var to_disp='<?php echo $to_disp?>';
    </script>
    in cases you would also need to use addslashes, but i didnt show it, you find it out

    Comment

    Working...