Question T2685
Visible to All Users

onComplete render completed survey, some text, JSON of result data

created 5 years ago

Using a single page survey.
Would like for onComplete to do the following:

  • Show completed survey (rendered with data user entered) ?maybe on #surveyResult? … can't get to work even with several examples I found online
    • validate survey as normal
    • no complete button after onComplete
  • Show some text instructions…currently seems to work with
    • document.querySelector('#surveyResult')
    • document.write('blah blah')
    • document.write('blah blah')
    • document.write('blah blah')
  • Show JSON of results…currently seems to work with
    • document.querySelector('#surveyResult')
    • document.write(JSON.stringify(result.data));

probably just confused on something. Currently I either don't see survey render and just text below OR nothing at all renders
Thanks.

Comments (1)

    sorry, wasn't sure what category to put this under. Might be bug since i did use clear(false,true), but may just be misuse.

    Answers approved by surveyjs Support

    created 5 years ago (modified 5 years ago)

    Hello,

    You can't render survey inside itself. That's why you see the same survey again.

    You need to create another survey instance. Here is the sample - https://plnkr.co/edit/AAhfhwz0YJBZhpZhbrm7?p=preview

    Thanks, Serge
    SurveyJS Team

      Comments (2)

        Thats cool, that’s what I needed.  Can you explain why that works and the other attempts didn’t.  Not sure I am understanding "

        You can't render survey inside itself. That's why you see the same survey again.
        You need to create another survey instance.

        Thank you.

        Javatexan

        On Sep 23, 2019, at 7:37 AM, Support Support <

          Hello,

          By this code you've cleared the survey state and re-render it. It will render in the original container, not in the results page markup.

          Code
          survey.clear(false, true); survey.render();

          Thanks, Serge
          SurveyJS Team

          created 5 years ago (modified 5 years ago)

          Hello,

          Survey has the completedHtml as well you can use corresponding selector to access HTML result content.
          Here is the working sample - https://plnkr.co/edit/G6YIQ0MTNOkLBVc5lBVG?p=preview

          Thanks, Serge
          SurveyJS Team

            created 5 years ago (modified 5 years ago)

            Hello,
            I did not get all your requirements. However, you may simply hide the survey div and display what ever you want.

            Thank you,
            Andrew
            SurveyJS Team

              Comments (3)

                I am using jquery.

                I have
                </head>
                <body>
                <div id="surveyElement"></div>
                <div id="surveyResult"></div>

                <script src="./index.js"></script>

                </body>

                onComplete I would like to show the finished survey with all the information entered and I would also like to show the surveyResult with some html in it with survey.data. Here is what I have so far. I now see the finished survey, but not the other stuff.

                survey.onComplete.add(function (result) {
                survey.clear(false, true);
                survey.render();
                $("#surveyResult").innerHTML =
                "<h1>THANK YOU for finishing your" + {reportname} + ". </h1>" +
                "<p> Do not forget to export <b>THIS PAGE</b> to LANDSCAPE 8x11.5 .pdf file to be uploaded to server. Use filename: YYYYMMDD-YOURID-"+{reportname}+".pdf" +
                "<p> Also copy this JSON into a .json file to upload to server as well." +
                "<p>" + survey.data;
                $("#surveyResult").show();

                });

                So I am wondering why now the #surveyElement is showing, but not the #surveyResult. If I used document.write to the page, I lose the #surveyElement drawing. Not sure what to try next for this.

                  Thanks for your plunker. I added the other clear and render and this is what I get.
                  https://plnkr.co/edit/5W1Zpo6TbIvSv7mSM2ez?p=preview
                  are completedhtml and the finished survey mutually exclusive?

                    Hello,

                    Could you please tell - what do you want to achieve by this code?

                    JavaScript
                    survey.clear(false, true); survey.render();

                    Thanks, Serge
                    SurveyJS Team

                    Other Answers

                    created 5 years ago

                    trying to show the completed survey with answers followed by the html