Page 1 of 1

XML code return does not function

PostPosted: Thu Oct 17, 2019 10:07 am
by John Robin Dove
Hi Clifton,
Sorry to bother you again so soon. I am using an XML file. It includes a section that handles the user event that you gave me:

Code: Select all
<function name="myUser" event="user" params="e">
        <![CDATA[
            /*   CLIFTON:  You can even make a user event on the sharedAction object.
                    To access the [value] parameter of the shared action:
                        var value = e.data OR use e.value
            ***/
         var returnValue;
         //My code is here and includes:!!
         returnValue = 1;
         return returnValue;
         ]]>
</function>


I call it from a shared action in the Toolbook DHTML and everything goes well except that it won't return anything. When I try to assign the return value to a variable I get undefined.

Re: XML code return does not function

PostPosted: Thu Oct 17, 2019 4:10 pm
by Clifton
To what object is the function assigned in the XML file?

Consider this XML snippet:
    <myObjectName>
    <function name="myUser" event="user" params="e">
    <![CDATA[
    var returnVal = 1 + "\n" + e.data;
    return returnVal;
    ]]>
    </function>
    </myObjectName>

To call this from a button click on another object:
    <myObjectName2>
    <!--This code assumes this object is a ToolBook object.-->
    <function name="myClick" event="click" params="evt,undef,target,mX,mY,isShift,isCntl" useTB="true">
    <![CDATA[
    //Send user event to get our returnVal
    var rtn = tbfunction_pgTBObjSet( "myObjectName", "user", "no data" );
    alert( rtn ); //rtn = "1 [cr] no data" if all goes well
    ]]>
    </function>
    </myObjectName2>

After you load this XML, clicking on myObjectName2 will send the user event to myObjectName and return the value of 1.
 

Re: XML code return does not function

PostPosted: Fri Oct 18, 2019 3:00 am
by John Robin Dove
Hi Clifton,

Thanks for your logical reply which put me back on the rails. I was getting a bit confused yesterday to put it mildly. I think only Harry Potter would have been able to make my code work!

The sequence was like this: selectbox => name of exercise => asynchronous Ajax request to read file => code to retrieve certain encrypted details => analysis of details => write cookie and go to a different URL to load and display exercise OR inform the user that the file had been illegally modified.

So at the last stage there was no object to which the return value could be returned. The solution was to use pgTBObjSet to send the return value to another object.

John