Dynamic variable into javascript variable

I am trying to put a dynamic variable using dmx.parse into a javascript function. The value is a date.

I know that ‘-’ and ‘/’ are a problem in javascript so it needs to be in a string. But even dynamic data passing an integer does not work. If I bind a static date to a variable this works “‘2012/12/31’” with double and single quotes. Any ideas?

<body is="dmx-app" id="test2" onload="test();">

<dmx-value id="testDate" dmx-bind:value="serverconnect1.data.query.dateArr"></dmx-value>
<script type="text/javascript">
                    function test() {
                var test1 = dmx.parse('testDate.value');
document.getElementById("demo").innerHTML = test1;
}
                </script>
                <p id="demo"></p>

Don’t see any problem in the code.
It could be a timing issue.
Try removing the function on load event… And call it manually from browser console. If that works, you need to add a delay to ensure dmx variable is loaded when JS function is being called.

Hi @sid thanks for your reply. I was using the on load event to delay the function until everything was a ready - I assume from what you are saying this is not the case?

Why not execute the function as a static event on success of the server connect?

Load event means page had loaded. It does not include initialization of all the other scripts that the page requires.

So DMX/AppConnect might not be ready at that point.

Thanks Sid, that explains it