none
Enable Save Button from Javascript Sharepoint 2013

    Question

  • Hi,

    I have created a survey for Employees who exit from the organization. The survey contains few questions that only employees should view and certain other questions which only respective HR can view and fill them. I have written the JavaScript for the same. Please find the same below:


    <style type="text/css">
      #s4-leftpanel{
    display:none
    }

    .s4-ca{
    margin-left:0px
    }
    </style>
    <script src="/sites/Unisys%20India%20Human%20Resource/SitePages/jquery-1.11.1.min.js"></script>
    <script type="text/javascript">

    var DOJ;
    var DOR;
    var DOL;
    var currenUser;
    var siteUrl = '/sites/Unisys%20India%20Human%20Resource';
    var userchec;
    var HrUser;
    var seconhr='G, Kezia Bernice';
    var thirdhr='Kumar, Krishna';
    var fourhr = 'V G, Shri Rajini Prriya';
    var fivthdhr = 'Appaiah, Priya Thothyana';
    var sixthhr = 'Agrawal, Abhishek';
    var sevhr = 'Casuba, Karuna';
    var eithhr='Danturti, Kameshwari';
    var ninhr='Kadathur, Srinivasan Madana Gopalan';
    var ten ='Ballal, Samata M';
    var eleven ='Vallachira, Jincy';

    ExecuteOrDelayUntilScriptLoaded(CurrtUser,'sp.js');


    function CurrtUser()                 /* Current User Checking  */
        {
              var context = SP.ClientContext.get_current(siteUrl);
               var siteColl = context.get_site();
               var web = siteColl.get_rootWeb();
               this._currentUser = web.get_currentUser();
               context.load(this._currentUser);
               context.executeQueryAsync(Function.createDelegate(this, this.CheckUserSucceededCurrentUser), Function.createDelegate(this, this.CheckUserfailedCurrentUser));
         }
    function CheckUserSucceededCurrentUser()
         {
          userchecs = this._currentUser.get_title();
        //  alert(userchecs);
         currenUser = document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff11_ctl00_ctl00_UserField_upLevelDiv').innerText.trim();
         var mgrUser = document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff111_ctl00_ctl00_UserField_upLevelDiv').innerText.trim();
         HrUser = document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff121_ctl00_ctl00_UserField_upLevelDiv').innerText.trim();
         userchecs == userchecs;
         HrUser == HrUser;
         
        
        /* 
         alert(seconhr);
         alert(thirdhr);
         alert(fourhr);
         alert(fivthdhr);
         alert(sixthhr);
         alert(sevhr);
         alert(eithhr);
         alert(ninhr);
        */
         
       //  alert(currenUser);
         if(userchecs==currenUser)
         {
          HRDisableCntr();
          document.getElementById('InterviewName').style.display='none';
          document.getElementById('HRPerspective').style.display='none';      
          document.getElementById('interviewCommments').style.display='none';
          document.getElementById('ReHireColumn').style.display='none';
          document.getElementById('OtherCommentsColumn').style.display='none';
          document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff61_ctl00_ctl00_DateTimeField_DateTimeFieldDate').disabled= true;      
              }
         else
         {
       
          if(userchecs==mgrUser)
          {
           HRDisableCntr();
          document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff431_ctl00_ctl00_TextField').disabled= true;
          document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff441_ctl00_ctl00_TextField').disabled= true;
          document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff61_ctl00_ctl00_DateTimeField_DateTimeFieldDate').disabled= true;
          }
          if((userchecs==HrUser)||(userchecs==seconhr)||(userchecs==thirdhr)||(userchecs==fourhr)||(userchecs==fivthdhr)||(userchecs==sixthhr)||(userchecs==sevhr)||(userchecs==eithhr)||(userchecs==ninhr) ||(userchecs==ten) ||(userchecs==eleven))
          {
           HRDisableCntr();
          }
         
          else {
          HRDisableCntr();
          document.getElementById('InterviewName').style.display='none';
          document.getElementById('HRPerspective').style.display='none';
          document.getElementById('ReHireColumn').style.display='none';      
          document.getElementById('interviewCommments').style.display='none';
          document.getElementById('OtherCommentsColumn').style.display='none';
          document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_savebutton1_ctl00_diidIOSaveItem').style.display='none';
          document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_savebutton2_ctl00_diidIOSaveItem').style.display='none';
          document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff61_ctl00_ctl00_DateTimeField_DateTimeFieldDate').disabled= true;

          }
         }
         
    document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_savebutton1_ctl00_diidIOSaveItem').onclick=function(){ValidateAlert();}
    document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_savebutton1_ctl00_diidIOSaveItem').onkeypress=function(){ValidateAlert();}

    document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_savebutton2_ctl00_diidIOSaveItem').onclick=function(){ValidateAlert();}
    document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_savebutton2_ctl00_diidIOSaveItem').onkeypress=function(){ValidateAlert();}
         
           }
    function CheckUserfailedCurrentUser()
           {
            alert('failed');
        }                               /* Current User Checking End  */

    function HRDisableCntr()
    {
     document.getElementById('InterviewName').style.display='block';
     document.getElementById('HRPerspective').style.display='block';
     document.getElementById('interviewCommments').style.display='block'; 
     document.getElementById('ReHireColumn').style.display='block';
     document.getElementById('OtherCommentsColumn').style.display='block';
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff11_ctl00_ctl00_UserField_upLevelDiv').disabled= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff21_ctl00_ctl00_TextField').readOnly= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff71_ctl00_ctl00_TextField').readOnly= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff81_ctl00_ctl00_TextField').readOnly= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff31_ctl00_DropDownChoice').disabled= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff91_ctl00_DropDownChoice').disabled= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff41_ctl00_ctl00_DateTimeField_DateTimeFieldDate').disabled= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff101_ctl00_DropDownChoice').disabled= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff51_ctl00_ctl00_DateTimeField_DateTimeFieldDate').disabled= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff111_ctl00_ctl00_UserField_upLevelDiv').disabled= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff61_ctl00_ctl00_DateTimeField_DateTimeFieldDate').disabled= false;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff121_ctl00_ctl00_UserField_upLevelDiv').disabled= true;
     document.getElementById('ReasonRow').disabled= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff141_ctl00_ctl00_TextField').readOnly= true;
     document.getElementById('WorkAssinRow').disabled= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff161_ctl00_ctl00_TextField').readOnly= true;
     document.getElementById('OpportRow').disabled= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff181_ctl00_ctl00_TextField').readOnly= true;
     document.getElementById('SupervRow').disabled= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff201_ctl00_ctl00_TextField').readOnly= true;
     document.getElementById('benefitRow').disabled= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff221_ctl00_ctl00_TextField').readOnly= true;
     document.getElementById('workCulRow').disabled= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff241_ctl00_ctl00_TextField').readOnly= true;
     document.getElementById('EmpEveRow').disabled= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff261_ctl00_ctl00_TextField').readOnly= true;
     document.getElementById('ReconRow').disabled= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff281_ctl00_ctl00_TextField').readOnly= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff291_ctl00_ctl00_TextField').readOnly= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff301_ctl00_ctl00_TextField').readOnly= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff311_ctl00_ctl00_TextField').readOnly= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff321_ctl00_ctl00_TextField').readOnly= true;
     document.getElementById('InfluRow').disabled=true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff341_ctl00_ctl00_TextField').readOnly= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff351_ctl00_ctl00_TextField').readOnly= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff361_ctl00_ctl00_TextField').readOnly= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff371_ctl00_ctl00_TextField').readOnly= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff381_ctl00_ctl00_TextField').readOnly= true; 
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff391_ctl00_ctl00_TextField').readOnly= true;
     document.getElementById('UGSIYN').disabled=true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff411_ctl00_ctl00_TextField').readOnly= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff421_ctl00_ctl00_TextField').readOnly= true;
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff11_ctl00_ctl00_UserField_browse').style.display='none';
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff121_ctl00_ctl00_UserField_browse').style.display='none';
     document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff111_ctl00_ctl00_UserField_browse').style.display='none';
      
      
    }
        
    function dataLoad()
    {
     DOJ = document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff41_ctl00_ctl00_DateTimeField_DateTimeFieldDate').value;
     DOR = document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff51_ctl00_ctl00_DateTimeField_DateTimeFieldDate').value;
     DOL = document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff61_ctl00_ctl00_DateTimeField_DateTimeFieldDate').value;
    }


    function ValidateAlert()
    {
      if((userchecs==HrUser)||(userchecs==seconhr)||(userchecs==thirdhr)||(userchecs==fourhr)||(userchecs==fivthdhr)||(userchecs==sixthhr)||(userchecs==sevhr)||(userchecs==eithhr)||(userchecs==ninhr) ||(userchecs==ten) ||(userchecs==eleven))
     
      {
       var txtInterviewName =  document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff431_ctl00_ctl00_UserField_upLevelDiv').innerText;
       var txtInterviewComment = document.getElementById('ctl00_m_g_0bdd7b5b_dc2b_4d05_9de1_2d64ea764e60_ff441_ctl00_ctl00_TextField').innerText;
       txtInterviewName = txtInterviewName.trim();
       txtInterviewComment = txtInterviewComment.trim();
       if((txtInterviewName.length==0)||(txtInterviewComment.length==0))
       {
        alert("Exit Interviewer’s Name / HR comment(s) / input(s) on actual “reason for leaving” - should not blank");
        return false;
       }
        
      
       var x=window.confirm("Please review and check for edits if any...\nAre you sure?");
       if (x == true)
       {
       document.getElementById('InfluRow').disabled= false;
       document.getElementById('UGSIYN').disabled=false;
       document.getElementById('ReconRow').disabled= false;
       document.getElementById('EmpEveRow').disabled= false;
       document.getElementById('workCulRow').disabled= false;
       document.getElementById('benefitRow').disabled= false;
       document.getElementById('SupervRow').disabled= false;
       document.getElementById('OpportRow').disabled= false;
       document.getElementById('WorkAssinRow').disabled= false;
       document.getElementById('ReasonRow').disabled= false;
       
       var button = $("input[id$='SaveItem']");
       var elementName = button.attr("name");
       WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", "", false, true));
       }
       else
       {
        return false;
       }
      }
     
      else
      
      {
       alert("You can't edit this Form\n Please Cancel the Form");
       return false;
      }
     
    }

     _spBodyOnLoadFunctionNames.push("dataLoad");


    </script>

    In this process, the save button and the cancel button of the SharePoint portal has been disabled. How to enable the buttons and also the disabled survey questions for all the HRs mentioned in the variables of the script.

    Please advice.

    Thanks.

    Monday, January 2, 2017 8:07 AM

All replies

  • Hi Kannaiav,

    According to your description, the “document.getElementById('<Save Button ID>').style.display='none';” script still be run when the current user is a HR.

    For this issue, please use F12 developer tools to debug the JavaScript and check the logic in your script.

    An article about how to debug JavaScript using F12 Developer tools:

    https://msdn.microsoft.com/en-us/library/gg699336(v=vs.85).aspx

    In addition, use the “else if” statement to specify a new condition if the first condition is false.

    For example:

    if (userchecs==currenUser) {     
       // if current user is currenUser
       // operations
    } else if (userchecs==mgrUser) {     
       // if current user is mgrUser
       // operations
    } else if ((userchecs==HrUser)||(userchecs==seconhr)||(userchecs==thirdhr)||(userchecs==fourhr)||(userchecs==fivthdhr)||(userchecs==sixthhr)||(userchecs==sevhr)||(userchecs==eithhr)||(userchecs==ninhr) ||(userchecs==ten) ||(userchecs==eleven)) {
       // if current user is a HR     
       // operations
     } else {
        // if current user is  not currenUser/mgrUser/a HR
        // operations
    }

    Best Regards,

    Linda Zhang


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, January 3, 2017 7:21 AM
    Moderator