Variable conversion PHP to Javascript.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NorKayak
    New Member
    • Jan 2015
    • 3

    Variable conversion PHP to Javascript.

    Hi;

    I'm a beginner and I'm getting a big headache figuring how to convert php variables into Javascript variables.
    I want to use the content of $theName as the value for an input tag. $_SESSION['$Sess_Name'] is loaded with the right data, I verified it. But my function InitField returns always the word NULL.
    Why is that? Where is the problem?

    Thanks

    Code:
    function InitField() {
        <?php
    	$theName = $_SESSION['$Sess_Name'];
        ?>
        var tempoVar = 	"<?php echo json_encode($theName); ?>";
        var myInput = document.getElementById('theName');
        myInput.value = tempoVar;
    }
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    But my function InitField returns always the word NULL.
    your function doesn’t have a return value.

    PS. it’s quite odd to name an array key with a $, which usually indicates a variable. may lead to confusion …

    Comment

    Working...