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

Try

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

jsb

Yes jsb, this works fine, thanks.

Bert

Hi - How did you get this to work? I have tried in a Control app with no success.
Thanks,
Larry