Value of a function in a global variable ?

Hi there
I try to set the value of a function into a global variable.
Every way I try didn’t work.

I just wann call this function once in my script to put the value of the grid into a global variable to use it in the hole script.
There is just one value in the grid, and I wanna set the value of 0 or 1 into a global variable auth.

AuthHiddenGrid = new dhtmlXGridObject('dummy'); AuthHiddenGrid.setHeader(""); AuthHiddenGrid.init(); auth = AuthHiddenGrid.loadXML("scripts/check_user.php",function(){ auth = AuthHiddenGrid.cells(1,0).getValue(); return auth; }) alert(auth);

the auth variable is always “undefined”… :frowning:

Sorry, I’m absolutly a beginner with javascript and dhtmlx.
Any ideas ?

Thanks a lot
Franky

Please, make sure that you are calling the variable after the data is completely loaded to the grid.
this one:

auth = AuthHiddenGrid.loadXML("scripts/check_user.php",function(){ auth = AuthHiddenGrid.cells(1,0).getValue(); alert(auth); return auth; })
or:

<input type="button" onclick="alert(auth)" value="push"> ... auth = AuthHiddenGrid.loadXML("scripts/check_user.php",function(){ auth = AuthHiddenGrid.cells(1,0).getValue(); return auth; });

Hello Sematik

Thanks for your reply! :slight_smile:

Sorry, but that didn’t works for me because I need the value into a variable, neather in a alert nor with a button assigned.

When the alert is in the function it works (var auth has value of the grid cell), but outside of the function the value of the variable auth is “undefined”.

I wanna call this function once at the very beginning of the code and store the value into a value where I can use in the hole script.

Any other ideas ?

Thanks !
Regards,
Franky

Please, make sure that the needed cell is already loaded to the grid.
If issue still occurs for you - please, provide us with a sample of your code so we can reproduce the issue and provide you a proper solution.

Hi

Attached I send you the code I use.
The PHP script gives back the remote calling IP in a “pseudo” (but valid!) grid cell.
If you use the example code, the first alert works fine with IP 127.0.0.1, but the second alert gives back “undefined”…
For me it looks like the value of auth ist correct in the function where the grid cell ist processed, but outside the value of auth ist undefined.

Thanks a lot for your help !!!
Best wishes
Franky

DHTMLX-Code:

AuthHiddenGrid = new dhtmlXGridObject(‘dummy’);
AuthHiddenGrid.setHeader("");
AuthHiddenGrid.init();
var auth = AuthHiddenGrid.loadXML(“scripts/check_user.php”,function(){
auth = AuthHiddenGrid.cells(1,0).getValue();
alert(“1 [”+auth+"]"); // <------- Right before the return the value of auth ist 127.0.0.1
return auth;
})
alert(“2 [”+auth+"]"); // <------- Here I wanna have the value of the grid cell, but is undefined

PHP-Script:

<?php echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" ;

echo “” ;
echo “<row id=“1”>” ;
echo “”.$_SERVER[‘REMOTE_ADDR’]."";
echo “” ;
echo “” ;
?>

Unfortunately at that it’s not available to find the value at that moment as the data is not loaded to the grid yet. Please, try to call it from a callback function of the load() method or in onXLE event.
docs.dhtmlx.com/doku.php?id=dhtm … vent_onxle