I had a recent request to change a survey’s “Respond to this Survey” text. Here’s two ways to do it, plus the “detective work” on how to do these kinds of changes.
If you just want the JavaScript solution then go ahead and scroll down to the end.
Solution 1: Don’t change it!
If your goal is to give the user a better way to start a survey, then just give them a direct link from Quick Launch, an Announcement or even an email. The “Respond to this Survey” button is just a link to the “Newform.aspx” for the survey and all you need to do is copy it. Here’s what the links look like:
SharePoint 2007 link:
http://yourserver/sites/yoursite/Lists/Survey%201/NewForm.aspx?Source=http%3A%2F%2Fyourserver%2Fsites%2Fyoursite%2FLists%2FSurvey%25201%2Foverview%2Easpx
SharePoint 2010 link:
http://yourserver/sites/yoursite/Lists/Test%20Survey/NewForm.aspx?IsDlg=1
Both of these give some interesting hints as to cool things you can do with these links:
- Redirect to another page on completion: In both 2007 and 2010 you can add “?Source=” and specify a page to go to after the survey has been completed. The destination (Source) could be the survey home page, the site’s home page or a custom “Thank you” page.
- Open the survey in a in a popup dialog box: In SharePoint 2010 you can add “?IsDlg=1” to the URL to open the survey formatted for a dialog box (more info below). Without this, the survey will be displayed as a normal SharePoint page.
- Note: You cannot use both “Source=” and “IsDlg” in the same URL as the user will just be redirected to a blank page.
To discover these links, just go to your survey and click “Respond to this Survey”. In SharePoint 2007 just copy the URL at the top of the browser. In SharePoint 2010, right-click inside of the dialog box and click Properties. From there you can copy the URL.
Now go to Quick Launch (Site Actions, Site Settings), a new Announcement, a new email, etc and paste the URL.
Adding to Quick Launch:
Here’s an example of using the link in Quick Launch. In the following example the URL will send them back to the home page after the survey has been completed:
http://yourserver/sites/yoursite/Lists/Survey%201/NewForm.aspx?Source=http://yourserver/sites/yoursite
As displayed in Quick Launch:
SharePoint 2010 and “IsDlg=1”
“IsDlg=1” alone is not enough to open a popup dialog box. “IsDlg=1” actually is an instruction to hide the master page content! So if you want to display just the survey and only the survey, add “IsDlg=1” to the URL.
Without “IsDlg=1”
With “IsDlg=1” (no Title, ribbon, Quick Launch, etc)
I’ll add an item to my “Blog To-Do” on show to actually display a page in a dialog box. (or you can just google/bing it!)
Solution 2: Change the “Respond to this Survey” text
Now for some detective work… Go to your survey page (overview.aspx). Right-click the page and select your browser’s “View Source” option. Search the displayed text for “Respond to this Survey”.
SharePoint 2010: (I replaced parts of the JavaScript with “…”)
<a id="ctl00_m_g_e2a6c7f0_8d5e_46a4_985f_8d175bfc5b24_ctl01_ctl00_toolBarTbl_RptControls_ctl00_diidIONewItem" accesskey="N" title="Respond to this Survey" onclick="javascript:NewItem2(event, ' ... ');return false;" href="javascript:__doPostBack(' ... ','');"> <img align='absmiddle' alt="Respond to this Survey" src="/_layouts/images/NewItem.gif" style='border-width:0px;' />   <span class="ms-splinkbutton-text">Respond to this Survey</span> </a>
SharePoint 2007:
<a id="ctl00_m_g_bcf319ff_0b26_4f28_b8d3_70cbf4e8152a_ctl00_ctl00_toolBarTbl_RptControls_ctl00_diidIONewItem" accesskey="N" title="Respond to this Survey" onclick="javascript:NewItem(' ... ');return false;" href="javascript:__doPostBack(' ... ','');"> <img align='absmiddle' alt="Respond to this Survey" src="/_layouts/images/NewItem.gif" style='border-width:0px;'> Respond to this Survey </a>
Just enough difference to be a nuisance! But note that in both we have three copies of “Respond to this Survey” to change. One in the A tag, one in the IMG tag and one at the end of the A tag (and for 2010, inside a SPAN tag).
Now for some detective work:
So how do we find the one A tag out of all of the HTML on this page? I never depend on IDs with lots of strange characters (they tend to change from page to page) so that leaves out the normal best solution: document.getElementById(“ctl00 ….. “). We could just loop through the A tags looking for one with a title of “Respond to this Survey”. And that will work fine, but as a best practice we may want this to work regardless of the language settings used to create the site.
So I see two other useful possibilities, find A tags with an ID that ends with “IONewItem” or find IMG tags that have ‘src="/_layouts/images/NewItem.gif"’. I’m going to use the first of these two.
So first let’s find the A tag:
var atags = document.getElementsByTagName("A"); for (var i=0;i<atags.length;i++) { if (atags[i].id.indexOf("IONewItem")>0) { // make text changes here... } }
Now let’s change the text:
The first change is easy. As we already have found the “A” tag (atags[i]) all we need to is change the title property:
var newsurveytext = "Click here for the survey!"; atags[i].title = newsurveytext;
The second change is not too hard… The A tag contains two or three child nodes and the first one is the image. All we need to do to it is change the ALT attribute:
atags[i].childNodes[0].alt = newsurveytext;
We need to be careful with the next part as we want it to work in both 2007 and 2010. As 2007 has two nodes (IMG and the text) and 2010 has three nodes (the IMG, the “ ” text and the SPAN) we just need to check the count of nodes to make the correct edit for each version:
if (atags[i].childNodes.length == 2) { // must be 2007 ("\u00A0" is to replace the ) atags[i].childNodes[1].nodeValue = "\u00A0" + newsurveytext; } else { // must be 2010 (and we hope the next version!) atags[i].childNodes[2].innerText = newsurveytext; }
So here’s the final solution:
<script> var atags = document.getElementsByTagName("A"); for (var i=0;i<atags.length;i++) { if (atags[i].id.indexOf("IONewItem")>0) { var newsurveytext = "Click here for the survey!"; atags[i].title = newsurveytext; atags[i].childNodes[0].alt = newsurveytext; if (atags[i].childNodes.length == 2) { // must be 2007 ("\u00A0" is to replace the ) atags[i].childNodes[1].nodeValue = "\u00A0" + newsurveytext; } else { // must be 2010 (and we hope the next version!) atags[i].childNodes[2].innerText = newsurveytext; } break; // no need to check the other A tags } } </script>
To add the JavaScript to SharePoint 2007
- Go to the survey page (overview.aspx)
- Click Site Actions and Edit Page
- Click Add a Web Part and select the Content Editor Web Part
- Move the Content Editor Web Part below the existing survey web part (important!)
- Edit the Content Editor Web Part and click the Source Editor button
- Copy and Paste the JavaScript above, changing the “newsurveytext” to your text
- Save and test
Or… edit the page (overview.aspx) in SharePoint Designer and add the JavaScript just be for the closing tag for the placeholder named “PlaceHolderMain”.
To add the JavaScript to SharePoint 2010
- Open Notepad, Copy and paste the JavaScript above, changing the “newsurveytext” to your text
- Save the file to a local drive
- Upload the file to a SharePoint library (while Shared Document will do, you may want a add a library just for these kinds of files)
- Go to the library where you just uploaded the file and copy the URL to the file (right-click the file and click Properties to find the URL)
- Go to the survey page (overview.aspx)
- Click Site Actions and Edit Page
- Click Add a Web Part and select the Content Editor Web Part
- Move the Content Editor Web Part below the existing survey web part (important!)
- Edit the Content Editor Web Part and paste the URL to the JavaScript file into the Content Link box
- Save and test
Or… edit the page (overview.aspx) in SharePoint Designer and add the JavaScript just be for the closing tag for the placeholder named “PlaceHolderMain”.
.
27 comments:
Hi Mike!
Thanks for your knowledge, i have a question though.
There are 2 options if im correct:
the ?source (redirect) and the ?IsDlg (show in full screen) option.
If i use them seperately, everything works fine. But if i use them in combination only one works.
Do you have any experience with this ?
Thanks a bunch!
Roland de Goeij.
Roland,
When you have more than one option in a query string, the first starts with "?" and all of the rest start with "@".
www.somesite.com/somepage.aspx?state=OH&city=Cincinnati&zip=45202
or in your example:
?source=abcdefgh&IsDlg=1
Mike
Make sure you put your code inside the tag with name 'PlaceHolderMain'. Otherwise it won't work.
Anonymous,
Or just put the code in a Content Editor Web Part as listed in the steps. If you do directly edit the page using SharePoint Designer, then you must put it in a placeholder. You can add it to any placeholder that loads after the web part, or add it to the end of PlaceHolderMain.
Mike
Thank you very much for this post.
I just a requirement for user for this & i implement your change & the result was good enough to wow the user.
Great post. I have multiple page survey. I want to redirect the user after the completion of the survey, If I use ?Source and IsDlg=1 in the same URL, they are not working.
Any idea of doing this.
Anonymous,
If there is more than one parameter in a URL, the first starts with "?" and the rest with "&".
yoururl?source=xxx&IsDlg=1
But, I'm not sure if the parameters are passed on to each page of a multi-page survey.
Let me know if this works...
Mike
Hi Mike,
Thank you very much for the post. I tried your solution 2, but it can only change the 'respond to this survey' button, what if I want to change the 'respond to this survey' text on the 'newitem' page? Is it possible?
Thanks,
Ivy
Ivy,
> what if I want to change the 'respond to this survey' text on the 'newitem' page?
Do you mean the NewForm.aspx page? If so, then yes, just edit the page using SharePoint Designer. This is covered in my book where I have an entire chapter on Surveys.
Mike
Is there a way to change the text on the new form page OOB without using SharePoint Designer?
Kathy L.
Yes. It is a web part page. There are detailed steps to edit Newform.aspx in my book.
Mike
Hi Mike -- is there a command that's similar to IsDlg=1 for 2007? All I'm trying to do is hide the nav/ribbon in a page viewer web part without making changes to the original page.
Thanks so much,
Sarah
Sarah,
Short answer: No
Longer answer...
See this article:
http://techtrainingnotes.blogspot.com/2009/05/sharepoint-list-whole-list-nothing-but.html
and also see the links in the comments at the end of that article.
Mike
Hi Mike, it's really useful to me, thanks a lot! I have another similar question. do you know what's the 'tags and notes' form page 'request url'? and the'I like it' (I found it's javascript) because I need to make them on my page myself by html tag. the defualt tags button has been blocked in masterpage definition. thanks!
Frank Wang
Thanks for your post!
when i use ?IsDlg i cannot scroll down.
Do you have any suggestion?!
thanks,
Anonymous,
The scroll bars should still work. Do you not see them at all? Has your master page been customized?
Mike
Thanks for the reply.
scroll bar doesn't show at all.
no my master page is not customized i am using v4.
if i change ?IsDlg=2 scroll bar show up but when i click the finis or cancel button then just a blank page appears!
any suggestions?
Is it possible to put a link on a different page that goes straight to the respond page in SP 2010? When I add the code on the page I want, it is there and works, till I close it. Then SharePoint removes the Javascript calls.
Bryon,
> Is it possible to put a link on a different page that goes straight to the respond page in SP 2010?
Yes
> Then SharePoint removes the Javascript calls
What page or what kind of page are you adding the disappearing link to?
Survey’s are a nice feature of SharePoint, however their security is not the easiest to understand.
I'm having the same issue as a previous commenter
Thanks for the reply.
scroll bar doesn't show at all.
no my master page is not customized i am using v4.
if i change ?IsDlg=2 scroll bar show up but when i click the finis or cancel button then just a blank page appears!
any suggestions?
Wondering if you had any suggestions?
Anonymouse,
Does your URL contain "Source="?
You cannot use both "Source=" and "IsDlg" in the same URL as the user will just be redirected to a blank page.
Mike
Thumbs Up!!
Great post! I did find an issue with 2010 that won't let me scroll with the ?IsDlg=1. Has anyone else found a way around this?
How do you create a link for editing existing saved survey?
Suthaharan,
Editing the questions or the responses?
Mike
Great Post Mike!
In SharePoint Designer 2010 I inserted a SharePoint Form Action Button control for my survey and used the 'commit' then 'redirect to page' so my users went to a thank you page when they clicked finish. This worked just like I wanted. However, now the cancel/goback button does not work. It does nothing at all. I tried similarly to insert a 'cancel' then 'redirect to page' but that still doesn't work. Do you have any suggestions for this issue? Thanks so much!
Post a Comment