How to add image in survey
- Dear all,
I need to embed an image at the first question in Survey.
Do you know how to do it?
Answers
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(/</g,'<').replace(/>/g,'>'); to the newForm.aspx and editForm.aspx
The JavaScript code replaces the escape characters (< and >) back to normal (< and >), then the image will be displayed.
Hope the information can be helpful.
-lambert
Sincerely,Lambert Qin | Microsoft TechNet Managed Forum SupportPosting is provided "AS IS" with no warranties, and confers no rights.- Marked As Answer byLambert QinMSFT, ModeratorThursday, September 03, 2009 6:17 AM
- Edited byLambert QinMSFT, ModeratorFriday, September 18, 2009 7:32 AM
All Replies
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(/</g,'<').replace(/>/g,'>'); to the newForm.aspx and editForm.aspx
The JavaScript code replaces the escape characters (< and >) back to normal (< and >), then the image will be displayed.
Hope the information can be helpful.
-lambert
Sincerely,Lambert Qin | Microsoft TechNet Managed Forum SupportPosting is provided "AS IS" with no warranties, and confers no rights.- Marked As Answer byLambert QinMSFT, ModeratorThursday, September 03, 2009 6:17 AM
- Edited byLambert QinMSFT, ModeratorFriday, September 18, 2009 7:32 AM
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 detailsUser 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%2EaspxKindly advise
- 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(/</g,'<').replace(/>/g,'>');
See my blog here for detailed steps: http://lambertqin.spaces.live.com/blog/cns!E93C48B467E6B3E1!1121.entry
Sorry for your inconverience.
-lambertSincerely,Lambert Qin | Microsoft TechNet Managed Forum SupportPosting is provided "AS IS" with no warranties, and confers no rights. - Hi Lambert,
Thank you very much! Now it is working well. 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.- 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(/</g,'<').replace(/>/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(/</g,'<').replace(/>/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 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.
-lambertSincerely,Lambert QinPosting is provided "AS IS" with no warranties, and confers no rights.
