1

How can I replaced SharePoint 2013 survey question text with image? I cant get the ms-formlabel class in my javascrip.

Below is the script I am Using:

<script language="JavaScript">

var className;
className = 'ms-formlabel';ms-formlabel

var elements = new Array();
var elements = document.getElementsByTagName('td');
for (var e = 0; e < elements.length; e++)
{
    if (elements[e].className == className)
    {
        elements[e].innerHTML = elements[e].innerHTML.replace('jj','<img src="/PublishingImages/icon-document.png"></img>');
    }
}

</script>
0

There is a workaround for you. I have created a survey list which has questions as below format

Image1

  • Enter Choice #1
  • Enter Choice #2
  • Enter Choice #3

Image2

  • Enter Choice #1
  • Enter Choice #2
  • Enter Choice #3

I used the text of the question as the token to find the right placeholder for the image and appended the image there using the below script.

function SetImage(){
var image1="<img src='/PublishingImages/icon-document.png'></img>"
var image1Question = $("table.ms-formtable .ms-formlabel:contains('jjj')");
$(image1Question).html("");
$(image1).appendTo(image1Question);
}

$(document).ready( function () {
    SetImage();
});

It works fine for me. Cheers.

  • Is it working in Sharepoint 2013 too? Because I cant get the class i.e. ms-formlabel. – akj Jun 6 '16 at 13:29
  • this gives me undefined for .html() – akj Jun 7 '16 at 3:50
  • The code i have shared is also tested in SP2013. Can you share the html format of the table where you are trying to find the class. – Nagarajan Muthukumar Jun 7 '16 at 6:28
  • <table class="ms-formtable" width="100%" cellspacing="0" cellpadding="0" border="0" style="margin-top: 8px;"> <tbody> <tr> <td class="ms-formlabel" width="90%" valign="top"> jjj </td> </tr> <tr> <td class="ms-formbody" width="90%" valign="top"> <span dir="none"> </span> </td> </tr> </tbody> </table> – akj Jun 7 '16 at 6:33
  • here, I can get object with class but i can't get inner html. It gives me undefined. so I can not replace text inside it. – akj Jun 7 '16 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.