Ask a questionAsk a question
 

AnswerHow to add image in survey

  • Tuesday, August 25, 2009 1:11 PMyoppie Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Dear all,

    I need to embed an image at the first question in Survey.
    Do you know how to do it?

Answers

  • Monday, August 31, 2009 7:08 AMLambert QinMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi,

     

    Customization is need to add the images in the survey, here is a way of replacing characters for your information.

     

    Here is the general steps for your information:

    1.    Suppose the first question of the survey is “Q1:XXX

    2.    You could add the insert the image code before the question text, the question should looks like: <img src="IMAGE_URL" />Q1:XXX

    3.    Then add JavaScript code: document.getElementsByTagName('Table').item(0).outerHTML=document.getElementsByTagName('Table').item(0).outerHTML.replace(/&lt;/g,'<').replace(/&gt;/g,'>'); to the newForm.aspx and editForm.aspx

    The JavaScript code replaces the escape characters (&lt; and &gt;) back to normal (< and >), then the image will be displayed.

     

     

    Hope the information can be helpful.

    -lambert


    Sincerely,
    Lambert Qin | Microsoft TechNet Managed Forum Support
    Posting is provided "AS IS" with no warranties, and confers no rights.

All Replies

  • Monday, August 31, 2009 7:08 AMLambert QinMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi,

     

    Customization is need to add the images in the survey, here is a way of replacing characters for your information.

     

    Here is the general steps for your information:

    1.    Suppose the first question of the survey is “Q1:XXX

    2.    You could add the insert the image code before the question text, the question should looks like: <img src="IMAGE_URL" />Q1:XXX

    3.    Then add JavaScript code: document.getElementsByTagName('Table').item(0).outerHTML=document.getElementsByTagName('Table').item(0).outerHTML.replace(/&lt;/g,'<').replace(/&gt;/g,'>'); to the newForm.aspx and editForm.aspx

    The JavaScript code replaces the escape characters (&lt; and &gt;) back to normal (< and >), then the image will be displayed.

     

     

    Hope the information can be helpful.

    -lambert


    Sincerely,
    Lambert Qin | Microsoft TechNet Managed Forum Support
    Posting is provided "AS IS" with no warranties, and confers no rights.
  • Friday, September 18, 2009 6:30 AMMike老杨 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi,
    I tried the way, currently I can saw picture in the survey when I click the "Respond to this Survey" button, but I got error after we finished the survey and click "Finish" button. The error as below:

    Webpage error details

    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; MS-RTC LM 8; aff-kingsoft-ciba)
    Timestamp: Fri, 18 Sep 2009 06:24:36 UTC

    Message: 'theForm.__EVENTTARGET' is null or not an object
    Line: 65
    Char: 9
    Code: 0
    URI:
    http://myteamssgp/sites/suzIT/Lists/testtest/NewForm.aspx?Source=http%3A%2F%2Fmyteamssgp%2Fsites%2FsuzIT%2FLists%2Ftesttest%2Foverview%2Easpx

     Kindly advise

  • Friday, September 18, 2009 7:32 AMLambert QinMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Mike,

    Yes, seems the JavaScript may also affect the script in Body tag, so I revise the script to  
    document.getElementsByTagName('Table').item(0).outerHTML=document.getElementsByTagName('Table').item(0).outerHTML.replace(/&lt;/g,'<').replace(/&gt;/g,'>');

    See my blog here for detailed steps: http://lambertqin.spaces.live.com/blog/cns!E93C48B467E6B3E1!1121.entry

    Sorry for your inconverience.
    -lambert
    Sincerely,
    Lambert Qin | Microsoft TechNet Managed Forum Support
    Posting is provided "AS IS" with no warranties, and confers no rights.
  • Monday, September 21, 2009 6:27 AMMike老杨 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Lambert,
    Thank you very much! Now it is working well.
  • Friday, October 30, 2009 2:50 AMrdcpro Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    A brilliant hack! I've been scratching my head for hours figuring out how to do this for a one-off survey. Great job, Lambert. 

    I might be a little cautious using this trick where the user can enter text, as it seems like there's a potential for cross site scripting, but I played around with it, and while I can get the answer text to display HTML (like the question), I can't seem to get javascript to execute...so maybe it's safe...

    Anyway, it's perfect for my needs tomorrow.

  • Saturday, October 31, 2009 8:05 PMrdcpro Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    When I implemented this, I made a few changes so it would work in Firefox, and to narrow the scope of what gets un-escaped:

    document.getElementById('onetIDListForm').rows[0].cells[0].innerHTML
        =
        document.getElementById('onetIDListForm').rows[0].cells[0].innerHTML.replace(/&lt;/g,'<').replace(/&gt;/g,'>');


    This works on the DispForm, NewForm and EditForm pages, but the Summary page doesn't have the same onetIDListForm cell, so I grabbed the ID of the web part zone TD cell:

     document.getElementById('MSOZoneCell_WebPartWPQ2').innerHTML
        =
        document.getElementById('MSOZoneCell_WebPartWPQ2').innerHTML.replace(/&lt;/g,'<').replace(/&gt;/g,'>');


    It still seems like there's a potential for XSS, so if you needed to use this on survey that had a textbox and where you would be concerned with XSS, you might want to modify the regex so it didn't un-escape <script tags.

    Anyway, thanks again for the idea--it made our company Halloween Contest a lot more fun to be able to use a SharePoint survey with photos. 

    Regards,
    Mike Sharp

  • Monday, November 02, 2009 7:04 AMLambert QinMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Mike,

    Thanks for your feedback and glad to know it helps for your issue.

    I agree with you, there should be a potential for XSS, but my expertise is not on Web Designer or security, I did think about much about this in the begining.

    You are right, narrow the scope would reduce the security risks and I would add to my blog.

    Thanks for your reply.

    -lambert


    Sincerely,
    Lambert Qin
    Posting is provided "AS IS" with no warranties, and confers no rights.