• Jairo Fiorentino
    November 2, 2018 at 1:33 pm #5323

    Hi,

    I have a coach, where there is a CustomHTML  control which contains a script tag and a javascript function defined.

    How I can call that function from a button defined in the same coach screen? That is, how to configure the button “on click” event to call the javascript function.

    Thanks, Jairo

    SPARK Support
    November 6, 2018 at 1:30 pm #5333

    Hi Jairo,

    You should be able to call the function from the On Click event, such as

    myAlert();

    which calls:

    Regards,

    Stephen P.

    Jairo Fiorentino
    November 6, 2018 at 1:57 pm #5336
    Hi Stephen,
    
    Thanks for your response.
    
    I'm trying the way you described. I have a Coach with 2 controls
    
    ** CustomHTML
    
    ** Button
    
    CustomHTML code is:
    
    <h3>Generate Random</h3>
    <script>
    function generateRandom() {
    var val = Math.floor(Math.random() * 100);
    // debugger statement
    debugger;
    Alert(“New value is “ + val);
    //# sourceURL=neil.js
    };
    </script>
    
    Button On-click event: generateRandom();
    
    The response I get on the browser debug screen is that generateRandom() function is not defined.
    There is an article that suggest it must be called as @generateRandom() but I think that worked for a previous version
    See the attached file.
    Thanks, Jairo
    SPARK Support
    November 7, 2018 at 8:19 am #5338

    Hi Jairo,

    There were two error in your script that once corrected executed correctly.

    First, alert() is case sensitive and should not be capitalized.

    Second, your quotes for “New value is ” need to be straight quotes, and not curly quotes like “ and ” .

    Regards,

    Stephen P.

    Jairo Fiorentino
    November 7, 2018 at 9:08 am #5339

    Hi Stephen,

    Thank you so much, that solved the problem … great 🙂

    Thanks, Jairo

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

Start typing and press Enter to search