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 app
created and survey published. If you haven't created an app
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.
-
Import the Survey123 web app API into your HTML page with the following:
Use dark colors for code blocks Copy <script src="https://survey123.arcgis.com/api/jsapi/"></script>
-
Create a web form instance with
client
andId item
values. For example:Id Use dark colors for code blocks Copy webform = new Survey123WebForm({ clientId: "TG75Zb6OXqL7jgcQ", container: "formDiv", itemId: "129132bbedcb490488a162aa996bb694" });
-
Dynamically set value on each question using the setQuestionValue method:
Use dark colors for code blocks Copy 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.