Visible Trigger - Show/Hide question(s) on survey running.
Open in new window

The visible trigger is called if the question value 'name' is changed.

The visible trigger makes the list of 'questions' and/or 'pages' visibles if the ('question' value 'operator' 'value') returns true. Otherwise the list of 'questions' and/or 'pages' becomes invisible.

The following 'operator' values are available: "empty", "notempty", "equal", "notequal", "greater", "less", "greaterorequal", "lessorequal", "contains" and "notcontains". The default value is "equal".


Survey.Survey.cssType = "bootstrap";
Survey.defaultBootstrapCss.navigationButton = "btn btn-green";

window.survey = new Survey.Model({
        triggers: [{ type: "visible", name: "type", operator: "equal", value: "Hot hatch", questions: ["Hot hatch"] },
                { type: "visible", name: "type", value: "sedan", questions: ["Sedan"] },
                { type: "visible", name: "type", value: "sports", questions: ["Sports"] },
                { type: "visible", name: "type", value: "Grand tourer", questions: ["Grand tourer"] },                
                { type: "visible", name: "type", value: "SuperCar", questions: ["Supercar"] },                
                { type: "visible", name: "type", value: "Muscle car", questions: ["Muscle car"] },                
                { type: "visible", name: "type", value: "Pony car", questions: ["Pony car"] },                
                { type: "visible", name: "type", value: "Convertible", questions: ["Convertible"] },                
                { type: "visible", name: "type", value: "other", questions: ["otherType"] }
            ],
        questions: [
                { type: "radiogroup",  name: "type", isRequired: true, colCount: 4, hasOther: true,
                title: "Please select the sport cars type.",
                choices: ["Hot hatch", "sedan|Sports saloon / sports sedan", "sports|Sports Car", "Grand tourer", "SuperCar", "Muscle car", "Pony car", "Convertible"]},
                { type: "radiogroup",  name: "Hot hatch", isRequired: true, colCount: 4, visible: false, title: "Please select the car", hasOther: true, choices: ["Honda Civic Type R", "Renault Megane RS", "Fiat 500 Abarth"]},
                { type: "radiogroup",  name: "Sedan", isRequired: true, colCount: 4, visible: false, title: "Please select the car", hasOther: true, choices: ["BMW M5", "Mazdaspeed6/Mazda 6 MPS", "Dodge Charger", "Dodge SRT-4", "Lotus Cortina", "Mitsubishi EVO"]},
                { type: "radiogroup",  name: "Sports", isRequired: true, colCount: 4, visible: false, title: "Please select the car", hasOther: true, choices: ["Chevrolet Corvette", "Mazda MX-5", "Porsche 911"]},
                { type: "radiogroup",  name: "Grand tourer", isRequired: true, colCount: 4, visible: false, title: "Please select the car", hasOther: true, choices: ["Aston Martin V8", "Lexus SC300/400", "Ferrari 612 Scaglietti"]},
                { type: "radiogroup",  name: "Supercar", isRequired: true, colCount: 4, visible: false, title: "Please select the car", hasOther: true, choices: ["McLaren P1", "Lamborghini Miura", "Bugatti Veyron 16.4"]},
                { type: "radiogroup",  name: "Muscle car", isRequired: true, colCount: 4, visible: false, title: "Please select the car", hasOther: true, choices: ["Ford Torino", "Plymouth Road Runner", "Pontiac GTO", "Ford Falcon", "Holden Monaro", "Valiant Charger"]},
                { type: "radiogroup",  name: "Pony car", isRequired: true, colCount: 4, visible: false, title: "Please select the car", hasOther: true, choices: ["AMC Javelin", "Chevrolet Camaro", "Dodge Challenger"]},
                { type: "radiogroup",  name: "Convertible", isRequired: true, colCount: 4, visible: false, title: "Please select the car", hasOther: true, choices: ["Honda S2000", "Volkswagen Eos", "Volvo C70"]},
                { type:"comment", name: "otherType", title: "Please describe the car.", isRequired: true, visible: false}
            ]});
survey.onComplete.add(function(result) {
	document.querySelector('#surveyResult').innerHTML = "result: " + JSON.stringify(result.data);
});


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


<!DOCTYPE html>
<html>

<head>
    <title>Welcome to JQuery</title>
    <script src="https://unpkg.com/jquery"></script>
    
    <script src="https://surveyjs.azureedge.net/0.12.18/survey.jquery.js"></script>
    
    
    <link rel="stylesheet" href="https://unpkg.com/bootstrap@3.3.7/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="./index.css">
</head>

<body>
    <div id="surveyElement"></div>
    <div id="surveyResult"></div>
    <script src="./index.js"></script>
</body>

</html>

.btn-green {
  background-color: #1ab394;
  color: #fff;
  border-radius: 3px;
}

.btn-green:hover, .btn-green:focus {
    background-color: #18a689;
    color: #fff;
}

.panel-footer {
    text-align: right;
    background-color: #fff;
}