Run Expression Trigger

On changing an answer, you may run an expression

                        function setCapitalAndCurrency(params) {
    if (params.length < 2) return;
    var country = params[0];
    var capitalQuestionName = params[1];
    var currencyQuestionName = params.length > 2 ? params[2] : null;
    var survey = this.survey;
    if (!country || !country.length) {
        survey.clearValue(capitalQuestionName);
        if (!!currencyQuestionName) {
            survey.clearValue(currencyQuestionName);
        }
        return;
    }
    survey.setVariable("request_processing", true);
    survey.setVariable("request_error", null);
    country = country.toLowerCase();
    $.ajax({
        url: "https://restcountries.eu/rest/v2/name/" + country,
        type: "GET",
        success: function (data) {
            if (!data || data.length < 1) return;
            var countryValue = data[0];
            survey.setValue(capitalQuestionName, countryValue.capital);
            var currencyValue = countryValue.currencies.length > 0 ? countryValue.currencies[0] : {};
            if (!!currencyQuestionName) {
                survey.setValue(currencyQuestionName, JSON.stringify(currencyValue));
            }
            survey.setVariable("request_processing", false);
        },
        error: function (xhr, ajaxOptions, thrownError) {
            survey.setVariable("request_error", "The country is not found.");
            survey.setVariable("request_processing", false);
            survey.clearValue(capitalQuestionName);
            if (!!currencyQuestionName) {
                survey.clearValue(currencyQuestionName);
            }
        }
    });
}
Survey.FunctionFactory.Instance.register("setCapitalAndCurrency", setCapitalAndCurrency);

    
        Survey.StylesManager.applyTheme("default");
    


var json = {
    questions: [
        { type: "text", name: "country", title: "Please enter the country" },
        { type: "html", name: "requesting", html: "The data is requesting", visibleIf: "{request_processing} = true" },
        { type: "text", name: "capital", title: "Capital of {country} is:", readOnly: true, visibleIf: "{capital} notempty" },
        { type: "text", name: "currency", title: "Currency in {country} is:", readOnly: true, visibleIf: "{currency} notempty" },
        { type: "html", name: "error", html: "The following error has happend: <b>{request_error}</b>", visibleIf: "{request_error} notempty" },
    ],
    triggers: [
        { type: "runexpression", expression: "{country} notempty or {country} empty", runExpression: "setCapitalAndCurrency({country}, 'capital', 'currency')" }
    ]
};

window.survey = new Survey.Model(json);


survey.onComplete.add(function(result) {
    document.querySelector('#surveyResult').innerHTML = "result: " + JSON.stringify(result.data);
});


$("#surveyElement").Survey({ 
    model: survey 
});


                    
<!DOCTYPE html>
<html>
<head>
    <title>On changing an answer, you may run an expression, jQuery Survey Library Example</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://unpkg.com/jquery"></script>
<script src="https://surveyjs.azureedge.net/1.0.55/survey.jquery.js"></script>
<link href="https://surveyjs.azureedge.net/1.0.55/survey.css" type="text/css" rel="stylesheet" />
    <link rel="stylesheet" href="./index.css">

</head>
<body>
                <div id="surveyElement">
            </div>
    <div id="surveyResult"></div>

<script type="text/javascript" src="./index.js"></script>

</body>
</html>