Announcement

Collapse
No announcement yet.

How to pass a global variable in sc to a java script variable

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to pass a global variable in sc to a java script variable

    I am using a javascript in the javascript option in a form and I want to pass a global variable to a variable in the javascript.
    How to do that more effcient than I do now?
    I now create a field username and pass a global variable to that field in de "on-load" event.

    {username} = [username];

    I have to hide this field because I donot want to use it in the form.

    Then I wrote in the javascript:

    usernamex = sc_getfield('username');
    var username = usernamex.value;

    Then I can use the "var username" in the rest of the javascript.

    But it seems a little complicated to me and looking for a more easy way.

    Kind regards,

    Bert

  • #2
    Try

    var username = <?php echo json_encode($_SESSION['username']); ?>;


    jsb

    Comment


    • #3
      Yes jsb, this works fine, thanks.

      Bert

      Comment

      Working...
      X