{"id":15,"date":"2011-02-04T23:45:15","date_gmt":"2011-02-04T17:45:15","guid":{"rendered":"http:\/\/markwheeler.com\/wordpress\/?p=15"},"modified":"2011-02-04T23:45:15","modified_gmt":"2011-02-04T17:45:15","slug":"sharepoint-2007-customer-satisfaction-survey","status":"publish","type":"post","link":"https:\/\/www.markwheeler.com\/?p=15","title":{"rendered":"Sharepoint 2007 Customer Satisfaction Survey"},"content":{"rendered":"<p>Had a requirement to build a customer satisfaction survey in Sharepoint.<\/p>\n<p>The survey had two fields that were to be populated by URL parameters.<\/p>\n<p>There are 5 questions with 5 potential answers each (radio buttons).<\/p>\n<p>Based on the a user selecting option 5 for question 1; a comments box was conditionally displayed.<\/p>\n<p>Here is the code I used&#8230;<\/p>\n<div id=\"_mcePaste\">\/\/ First snippet here is to kill the Save button on the Survey form.<\/div>\n<div>&lt;script type=&#8221;text\/javascript&#8221;&gt;<\/div>\n<div id=\"_mcePaste\">_spBodyOnLoadFunctionNames.push(&#8220;setValue&#8221;);<\/div>\n<div id=\"_mcePaste\">function setValue() {<\/div>\n<div id=\"_mcePaste\">hideButton(&#8220;Save&#8221;);<\/div>\n<div id=\"_mcePaste\">}<\/div>\n<div id=\"_mcePaste\">\/\/This function hides a button on the page<\/div>\n<div id=\"_mcePaste\">function hideButton(valueDef){<\/div>\n<div id=\"_mcePaste\">var frm = document.forms[0];<\/div>\n<div id=\"_mcePaste\">for (i=0;i&lt; frm.elements.length;i++) {<\/div>\n<div id=\"_mcePaste\">if (frm.elements[i].type == &#8220;button&#8221; &amp;&amp; frm.elements[i].value == valueDef) {<\/div>\n<div id=\"_mcePaste\">frm.elements[i].style.display = &#8220;none&#8221;;<\/div>\n<div id=\"_mcePaste\">}<\/div>\n<div id=\"_mcePaste\">}<\/div>\n<div id=\"_mcePaste\">}<\/div>\n<div id=\"_mcePaste\">&lt;\/script&gt;<\/div>\n<div>\/\/ Second snippet uses <a href=\"http:\/\/sputility.codeplex.com\/\" target=\"_blank\" rel=\"noopener\">SPUTILITY.js<\/a> to grab the URL parameters and also hide\/show comments field.<\/div>\n<div id=\"_mcePaste\">&lt;script type=&#8221;text\/javascript&#8221; src=&#8221;prototype.js&#8221;&gt;&lt;\/script&gt;<\/div>\n<div id=\"_mcePaste\">&lt;script type=&#8221;text\/javascript&#8221; src=&#8221;SPUtility.js&#8221;&gt;&lt;\/script&gt;<\/div>\n<div id=\"_mcePaste\">&lt;script type=&#8221;text\/javascript&#8221;&gt;<\/div>\n<div id=\"_mcePaste\">_spBodyOnLoadFunctionNames.push(&#8220;hide&#8221;);<\/div>\n<div id=\"_mcePaste\">_spBodyOnLoadFunctionNames.push(&#8220;SetValueFromURL(&#8216;FIELD1&#8242;, URLPARAM1&#8217;)&#8221;);<\/div>\n<div id=\"_mcePaste\">_spBodyOnLoadFunctionNames.push(&#8220;SetValueFromURL(&#8216;FIELD2&#8217;, &#8216;URLPARAM2&#8217;)&#8221;);<\/div>\n<div id=\"_mcePaste\">function SetValueFromURL(fieldName,queryParamName) {<\/div>\n<div id=\"_mcePaste\">var queryParams = location.href.toQueryParams();<\/div>\n<div id=\"_mcePaste\">if (queryParams != null &amp;&amp; queryParams[queryParamName] != null) {<\/div>\n<div id=\"_mcePaste\">SPUtility.GetSPField(fieldName).SetValue(decodeURI(queryParams[queryParamName])).MakeReadOnly();<\/div>\n<div id=\"_mcePaste\">}<\/div>\n<div id=\"_mcePaste\">}<\/div>\n<div id=\"_mcePaste\">function hide() {<\/div>\n<div id=\"_mcePaste\">SPUtility.GetSPField(&#8216;Comments&#8217;).Hide();<\/div>\n<div id=\"_mcePaste\">}<\/div>\n<div id=\"_mcePaste\">&lt;\/script&gt;<\/div>\n<div>\/\/ The tricky part&#8230; Find the Radio Buttons for Question 1 and assign OnClick event handlers. You have to view the source of your form to find these.<\/div>\n<div id=\"_mcePaste\">&lt;script type=&#8221;text\/javascript&#8221; language=&#8221;javascript&#8221;&gt;<\/div>\n<div id=\"_mcePaste\">\/\/ Initiate InitLoad () function on the load event of your editForm.aspx<\/div>\n<div id=\"_mcePaste\">window.attachEvent(&#8220;onload&#8221;,InitLoad);<\/div>\n<div id=\"_mcePaste\">\/\/in this function, assign event handlers to your controls<\/div>\n<div id=\"_mcePaste\">function InitLoad() {<\/div>\n<div id=\"_mcePaste\">\/\/declaring the first radio button and attaching \u201conclick\u201d event handler to it<\/div>\n<div id=\"_mcePaste\">var Q1D = document.getElementById(&#8220;ctl00_m_g_8a1be6f2_c21e_4b9b_9dac_46a7bc9aec80_ctl00_ctl01_ctl02_ctl00_ctl00_ctl04_ctl00_ctl04&#8221;);<\/div>\n<div id=\"_mcePaste\">Q1D.attachEvent(&#8220;onclick&#8221;,showFields);<\/div>\n<div id=\"_mcePaste\">var Q1C = document.getElementById(&#8220;ctl00_m_g_8a1be6f2_c21e_4b9b_9dac_46a7bc9aec80_ctl00_ctl01_ctl02_ctl00_ctl00_ctl04_ctl00_ctl03&#8221;);<\/div>\n<div id=\"_mcePaste\">Q1C.attachEvent(&#8220;onclick&#8221;,showFields);<\/div>\n<div id=\"_mcePaste\">var Q1B = document.getElementById(&#8220;ctl00_m_g_8a1be6f2_c21e_4b9b_9dac_46a7bc9aec80_ctl00_ctl01_ctl02_ctl00_ctl00_ctl04_ctl00_ctl02&#8221;);<\/div>\n<div id=\"_mcePaste\">Q1B.attachEvent(&#8220;onclick&#8221;,showFields);<\/div>\n<div id=\"_mcePaste\">var Q1A = document.getElementById(&#8220;ctl00_m_g_8a1be6f2_c21e_4b9b_9dac_46a7bc9aec80_ctl00_ctl01_ctl02_ctl00_ctl00_ctl04_ctl00_ctl01&#8221;);<\/div>\n<div id=\"_mcePaste\">Q1A.attachEvent(&#8220;onclick&#8221;,showFields);<\/div>\n<div id=\"_mcePaste\">var Q1 = document.getElementById(&#8220;ctl00_m_g_8a1be6f2_c21e_4b9b_9dac_46a7bc9aec80_ctl00_ctl01_ctl02_ctl00_ctl00_ctl04_ctl00_ctl00&#8221;);<\/div>\n<div id=\"_mcePaste\">Q1.attachEvent(&#8220;onclick&#8221;,showFields);<\/div>\n<div id=\"_mcePaste\">}<\/div>\n<div id=\"_mcePaste\">function showFields(){<\/div>\n<div id=\"_mcePaste\">var Q1D = document.getElementById(&#8220;ctl00_m_g_8a1be6f2_c21e_4b9b_9dac_46a7bc9aec80_ctl00_ctl01_ctl02_ctl00_ctl00_ctl04_ctl00_ctl04&#8221;);<\/div>\n<div id=\"_mcePaste\">if (Q1D.checked==true){<\/div>\n<div id=\"_mcePaste\">SPUtility.GetSPField(&#8216;Comments&#8217;).Show();<\/div>\n<div id=\"_mcePaste\">\/\/ alert(&#8216;Onlick Works&#8217;);<\/div>\n<div id=\"_mcePaste\">}<\/div>\n<div id=\"_mcePaste\">var Q1C = document.getElementById(&#8220;ctl00_m_g_8a1be6f2_c21e_4b9b_9dac_46a7bc9aec80_ctl00_ctl01_ctl02_ctl00_ctl00_ctl04_ctl00_ctl03&#8221;);<\/div>\n<div id=\"_mcePaste\">if (Q1C.checked==true){<\/div>\n<div id=\"_mcePaste\">SPUtility.GetSPField(&#8216;Comments&#8217;).Hide();<\/div>\n<div id=\"_mcePaste\">\/\/ alert(&#8216;Onlick Works&#8217;);<\/div>\n<div id=\"_mcePaste\">}<\/div>\n<div id=\"_mcePaste\">var Q1B = document.getElementById(&#8220;ctl00_m_g_8a1be6f2_c21e_4b9b_9dac_46a7bc9aec80_ctl00_ctl01_ctl02_ctl00_ctl00_ctl04_ctl00_ctl02&#8221;);<\/div>\n<div id=\"_mcePaste\">if (Q1B.checked==true){<\/div>\n<div id=\"_mcePaste\">\/\/ declare my metadata field \u201cRelated Documents\u201d to be hidden using the ID from \u201cView Source\u201d<\/div>\n<div id=\"_mcePaste\">SPUtility.GetSPField(&#8216;Comments&#8217;).Hide();<\/div>\n<div id=\"_mcePaste\">\/\/ alert(&#8216;Onlick Works&#8217;);<\/div>\n<div id=\"_mcePaste\">}<\/div>\n<div id=\"_mcePaste\">var Q1A = document.getElementById(&#8220;ctl00_m_g_8a1be6f2_c21e_4b9b_9dac_46a7bc9aec80_ctl00_ctl01_ctl02_ctl00_ctl00_ctl04_ctl00_ctl01&#8221;);<\/div>\n<div id=\"_mcePaste\">if (Q1A.checked==true){<\/div>\n<div id=\"_mcePaste\">\/\/ declare my metadata field \u201cRelated Documents\u201d to be hidden using the ID from \u201cView Source\u201d<\/div>\n<div id=\"_mcePaste\">SPUtility.GetSPField(&#8216;Comments&#8217;).Hide();<\/div>\n<div id=\"_mcePaste\">\/\/ alert(&#8216;Onlick Works&#8217;);<\/div>\n<div id=\"_mcePaste\">}<\/div>\n<div id=\"_mcePaste\">var Q1 = document.getElementById(&#8220;ctl00_m_g_8a1be6f2_c21e_4b9b_9dac_46a7bc9aec80_ctl00_ctl01_ctl02_ctl00_ctl00_ctl04_ctl00_ctl00&#8221;);<\/div>\n<div id=\"_mcePaste\">if (Q1.checked==true){<\/div>\n<div id=\"_mcePaste\">\/\/ declare my metadata field \u201cRelated Documents\u201d to be hidden using the ID from \u201cView Source\u201d<\/div>\n<div id=\"_mcePaste\">SPUtility.GetSPField(&#8216;Comments&#8217;).Hide();<\/div>\n<div id=\"_mcePaste\">\/\/ alert(&#8216;Onlick Works&#8217;);<\/div>\n<div id=\"_mcePaste\">}<\/div>\n<div id=\"_mcePaste\">}<\/div>\n<div id=\"_mcePaste\">&lt;\/script&gt;<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Had a requirement to build a customer satisfaction survey in Sharepoint. The survey had two fields that were to be populated by URL parameters. There are 5 questions with 5 potential answers each (radio buttons). Based on the a user selecting option 5 for question 1; a comments box was [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[10],"tags":[98,113],"class_list":["post-15","post","type-post","status-publish","format-standard","hentry","category-sharepoint","tag-sharepoint","tag-survey"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts\/15","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=15"}],"version-history":[{"count":0,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts\/15\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}