Embed a survey using JavaScript

You can use JavaScript to embed, style, and interact with a survey in your custom web app.

Prerequisites

The following steps require you to already have an appID created and survey published. If you haven't created an appID yet, follow the instructions to Add and register an app in ArcGIS Online or Add and register an app in ArcGIS Enterprise. If you do not already have a survey see Create and publish a survey.

Steps

Embed a survey in your web app by referencing its clientId and itemId.

  1. Import the Survey123 web app API into your HTML page with the following:

    1
    <script src="https://survey123.arcgis.com/api/jsapi/"></script>
  2. Create a web form instance with clientId and itemId values. For example:

    1
    2
    3
    4
    5
    webform = new Survey123WebForm({
        clientId: "TG75Zb6OXqL7jgcQ",
        container: "formDiv",
        itemId: "129132bbedcb490488a162aa996bb694"
    });
  3. Dynamically set value on each question using the setQuestionValue method:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    webform.setQuestionValue({
       'ReportDate': '2024-09-01',
       'Location': {
           x: 129.1236,
           y: 29.1236,
           spatialReference: {
             wkid: 4326
           }
       },
       'HoursFished': 10,
       'WaterbodyName': 'Little river',
       'Weather': 'rain',
       // This is a repeat question
       'CapturedFish': [{
         'Species': 'Paddlefish',
         'FishSize': 5,
         'FishWeight': 10,
         'condition': 'normal',
         'fishPosition': {
           x: 161.123,
           y: 29.123
         }
       },{
        'Species': 'Trout',
         'FishSize': 7,
         'FishWeight': 12,
         'condition': 'poor',
         'fishPosition': {
           x: 169.123456,
           y: 19.123456
         }
       }]
     });

What's next?

For a complete list of JavaScript properties and methods, see the Survey123 web app API reference.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close