March 31, 2011

Hide "SAVE" button from SharePoint survey

This is another requirement came from user:
His intesion is to hide "SAVE" button from the survey, when it is having link from one question to another.
here the problem is if a survey contails sutch linking pages from question to question, it show "NEXT" "SAVE" "CANCEL" buttos. if user clicks "SAVE" buttot at first question itself the survey end's and the survey comes under incompleted list. which is not expecting the functionality; so by using jquery we can hide the "SAVE" button.

1) Firstofall go to your survey page by clicking "Respond to Survey".
now in the URL after NewForm.aspx add ?PageView=Shared&ToolPaneView=2
like: http://xxxxxxx/xxxxx/NewForm.aspx?PageView=Shared&ToolPaneView=2  , now it will convert the page into edit mode.

2)Now add a content editor web part and copy the below two sections of the scripts in to content editor web part and exit from edit mode, and see the magic :) "SAVE" button will be hidden.
==================================================
//section 1
<script type="text/javascript">
 if(typeof jQuery=='undefined'){
  var jQPath = 'http://ajax.googleapis.com/ajax/libs/jquery/1.3/';
  document.write('<script src="',jQPath,'jquery.min.js" type="text/javascript"><\/script>');
 }
</script>

//section 2
<script type="text/javascript">
$(function() {
 $(":inputs[value='Save']").hide();
  });
</script>
==================================================
so what section 1 will do?
first it will check whether the jquery library included in page or not [it is very important to include jquery library as we are using jquery to hide the button]

what section 2 will do?
it will find Save button and hide it.

thats it...... :)

8 comments:

  1. Hi,
    Can I also hide 'cancel' with this code by just exchanging 'save' for 'cancel'?

    ReplyDelete
    Replies
    1. Yes You can, but you need to Change
      $(":inputs[value='Save']").hide();
      to
      $(":inputs[value='Cancel']").hide();

      Delete
  2. Thx, when i use "?PageView=Shared&ToolPaneView=2" after starting the survey then i can edit the first question of the survey and hide the save button with your script. But how can i edit the following questions of the survey? There is still a Save Button and "?PageView=Shared&ToolPaneView=2" doesn't work here.

    btw: your download link is broken. Could you fix it. please?

    Thx for your reply!

    ReplyDelete
    Replies
    1. Hi , With your 1st Question:

      is that you enabled Branching logic in the Survey ? [if enabled, the first question come up with 3 buttos "Next" "Save" "Cancel"]. if so when you answer first question and select "Next" it will redirect to the next question according to Branching Logic and opens further questions in EditForm.aspx. so after this you can use "?PageView=Shared&ToolPaneView=2" and add the CEWP with script.

      2nd Question:
      updated the 2nd point, the link is expired. its simply a CEWP. add it and pase the script.

      Delete
  3. Hello Girish,
    Thank you for you post, you are so great. Good teaching and explaination skills, coupled with timely and proper response to questions. Are you on linkedin? Cheers

    ReplyDelete
  4. Hi Girish

    Thank you for the code...it works.

    One question: for the code to work, it prompts me with a security warning "do you want to view only the webpage content that was delivered securely?"

    Any chance how can this be avoided?

    ReplyDelete
    Replies
    1. Your issue is related to IE Config settings, i hope the below links will help you [if not do revert back]:

      Solution 1

      OR

      Solution2

      Delete
    2. Super !!!!!!!!!!!! Thank yoy it worked great ...!!!

      Delete