Buy Licenses Contact Support Login/Register
v 1.7.19
v 1.7.19
Overview Examples Docs Source Download

One choice - Dropdown question

One choice - dropdown (type:'dropdown')


                        
        
            Survey.StylesManager.applyTheme("modern");
        


            
                var json = { questions: [
    { type: "dropdown", name: "car", title: "What car are you driving?", isRequired: true, colCount: 0,
        choices: ["None", "Ford", "Vauxhall", "Volkswagen", "Nissan", "Audi", "Mercedes-Benz", "BMW", "Peugeot", "Toyota", "Citroen"] }
]};

                window.survey = new Survey.Model(json);
            
        
            survey.onComplete.add(function(result) {
            document.querySelector('#surveyResult').textContent =
            "Result JSON:\n" + JSON.stringify(result.data, null, 3);
            });
        
        
            $("#surveyElement").Survey({
            model: survey 
            });
        

                    
<!DOCTYPE html>
<html lang="en">
<head>
    <title>One choice - dropdown (type:&#39;dropdown&#39;), jQuery Survey Library Example</title>

<meta name="viewport" content="width=device-width" />
    <script src="https://unpkg.com/jquery"></script>
<script src="https://surveyjs.azureedge.net/1.7.19/survey.jquery.js"></script>
<link href="https://surveyjs.azureedge.net/1.7.19/modern.css" type="text/css" rel="stylesheet" />
    <link rel="stylesheet" href="./index.css">

</head>
<body>
    
            <div id="surveyElement" style="display:inline-block;width:100%;">
            </div>
    <div id="surveyResult"></div>

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

</body>
</html>
There are several ways to set the 'choices' property.
// The classic way to set the property. The result values are numbers: 1 and 2
choices: [{ value: 1, text: "Value 1" }, { value: 2, text: "Value 2" }]
// The values are: 1 and 'Value 2' and texts are '1' and 'Value 2'
choices: [{ value: 1 }, { value: "Value 2" }]
// The values and texts are same
choices: ["Value 1", "Value 2"]
// The values are '1' and '2' and texts are 'Value 1' and 'Value 2'
choices: ["1|Value 1", "2|Value 2"]
settings

Choices order: (default is 'none')

var q = survey.getQuestionByName('car');
q.choicesOrder = yourvalue; 
survey.render();

var q = survey.getQuestionByName('car');
q.hasOther = yourvalue; 
survey.render();

Others text

var q = survey.getQuestionByName('car');
q.otherText = yourvalue; 
survey.render();