Skip to content

Javascript helpers

We have added several functions (named 'helpers') so you can quickly and easily interact with your app from your Javascript code (or from HTML onclick functions).

srnSetVariableValue(varName, value)

Use this function to set the value of a variable.

You can use it in Javascript code:

var y = new Date().getFullYear();
srnSetVariableValue("myVar", y);

Or you can use it in HTML code:

<div>
    <div class='filter_entry {{varCountry=="Europe"? "entry_selected":"entry_not_selected"}}'
        onclick='srnSetVariableValue("varCountry", "Europe")'>
        Europe
    </div>
    <div class='filter_entry {{varCountry=="USA"? "entry_selected":"entry_not_selected"}}'
        onclick='srnSetVariableValue("varCountry", "USA")'>
        United States Of America
    </div>
    <div class='filter_entry {{varCountry=="Asia"? "entry_selected":"entry_not_selected"}}'
        onclick='srnSetVariableValue("varCountry", "Asia")'>
        Asia
    </div>
</div>

srnToogleValueInList(varNameOfTheList, valueToToogle)

If the value is in the list, it is removed, else it is added to the list.

You can use it in javascript code:

srnToogleValueInList("varCountries", "Europe");

You can also use it directly in HTML code:

<div>
    <div class='filter_entry {{variableIncludes("varCountries","Europe")? "entry_selected":"entry_not_selected"}}'
            onclick='srnToogleValueInList("varCountries", "Europe")'>
        Europe
    </div>
    <div class='filter_entry {{variableIncludes("varCountries","USA") ? "entry_selected":"entry_not_selected"}}'
            onclick='srnToogleValueInList("varCountries", "USA")'>
        United States Of America
    </div>
    <div class='filter_entry {{variableIncludes("varCountries","Asia") ? "entry_selected":"entry_not_selected"}}'
            onclick='srnToogleValueInList("varCountries", "Asia")'>
        Asia
    </div>
</div>

srnLogout()

This function logs out the current user.

srnLogout()
<div onclick="srnLogout()">
    LOGOUT SERENYTICS
</div>