Show SharePoint Survey Friendly message using jQuery

This SharePoint tutorial, we will discuss how to show SharePoint survey friendly message using jQuery in SharePoint 2010/2013/2016 or SharePoint Online.

Once we submit the survey response, still it allows us to click on the respond survey link but after this, it displays an ugly message.

Show SharePoint Survey Friendly message using jQuery

Show SharePoint Survey Friendly message using jQuery

I had a requirement where the Survey Link was set in the tiles web part and we had to display a custom message if the survey has been already submitted.

Show SharePoint Survey Friendly message using jQuery

Please find the below code to achieve the requirement. Create .js file and place the code, make sure you change the Tile Div ID according to your client id.

Provide the .js file reference in the page where the Survey link has been provided.

var linkTitle;
var linkOrginal;
var linkMessage;
$(document).ready(function ()

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {
$('a[id^=Tile_WPQ]').click(function(e) {
linkTitle = $(this).attr("id");
linkOrginal= $(this).attr('href');
if (linkTitle == "Tile_WPQ10_1_3")

var collListItems ;
var currentUser = null;
var web;
var context;
var list;
var viewXml;
var query;
function getWebSiteData() {
context = new SP.ClientContext.get_current();
web = context.get_web();
currentUser = web.get_currentUser();
list = web.get_lists().getByTitle('Survey');
var query= new SP.CamlQuery();
query.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'Author\' LookupId=\'TRUE\' /><Value Type=\'Integer\'><UserID /></Value></Eq></Where></Query></View>');

collListItems = list.getItems(query);
Function.createDelegate(this, this.onSuccessMethod),
Function.createDelegate(this, this.onFailureMethod));
//context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));
function onSuccessMethod(sender, args)
var votesCount = this.collListItems.get_count();
if(votesCount > 0)
// window.alert('You have already voted to this survey.');
// + '/Pages/Survey-Message.aspx');
window.location.href = this.web.get_url()+ '/Pages/Survey-Message.aspx';

else {

function onFailureMethod(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());

You may like following SharePoint tutorials:

This SharePoint tutorial we learned how to show SharePoint Survey Friendly message using jQuery.

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)


Sambita Rath

I have 9 years of exprience into SharePoint implementation, architecture, Administrator, development and Training.Designing Information Architecture in SharePoint 2007, 2010,2013 and Office 365.