Hey Team,
I am using Survey creator with React.
I want to run a javascript function like onclick event handlers, with the html type questions.
Here's html markup:
HTML<button onclick="myFunction()">Click me</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Hello World";
}
</script>
Here's my survey json:
Code{
"title": "Demo Survey 1",
"logoPosition": "right",
"completedHtml": "<h3>Thank you for your feedback</h3>",
"completedHtmlOnCondition": [
{
"html": "<h3>Thank you for your feedback</h3> <h4>We are glad that you love our product. Your ideas and suggestions will help us make it even better.</h4>"
},
{
"html": "<h3>Thank you for your feedback</h3> <h4>We are glad that you shared your ideas with us. They will help us make our product better.</h4>"
}
],
"pages": [
{
"name": "page1",
"elements": [
{
"type": "text",
"name": "question1",
"title": "What is your name?",
"isRequired": true
}
]
},
{
"name": "page2",
"elements": [
{
"type": "html",
"name": "info",
"html": "\n<button onclick=\"myFunction()\">Click me</button>\n\n<p id=\"demo\"></p>\n\n<script>\nfunction myFunction() {\n document.getElementById(\"demo\").innerHTML = \"Hello World\";\n}\n</script>"
},
{
"type": "text",
"name": "question2",
"title": "What is your age?"
}
]
}
],
"showQuestionNumbers": "off"
}
But here it throws error on click:
CodeUncaught ReferenceError: myFunction is not defined
at HTMLButtonElement.onclick (123:1:1)
Can you help me with this?
Thanks
Timi