Javascript in sharepoint not working -


i have been tasked taking expense report list , adding approve button change drop down of each item in list approved. working through several tutorials on how use javascript inside sharepoint banging head against wall trying figure out why code not running. have added asp:button asp:content area, , script tag function in it. see below:

<asp:button runat="server" text="approve all" id="approvebutton" onclientclick="dosomething()"></asp:button> <script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script> <script type="text/javascript" src="/_layouts/15/sp.js"></script> <script type="text/javascript">      function dosomething()     {          var clientcontext = sp.clientcontext();         //var olist = clientcontext.get_web().get_lists().getbytitle('b612de4b-f85c-4492-8877-8c2b07ae187d');         //clientcontext.load(olist);         //clientcontext.executequeryasync(         //  function.createdelegate(this, this.onquerysucceeded),         //  function.createdelegate(this, this.onqueryfailed)         //  );          alert("should done");         //$("#{26787edd-bcdc-41d2-abee-249747203be8}-{69f3e959-eb93-458f-a4cd-e1aca2335d10}").hide("slow");         //$("#ctl00_onetidheadbnnr2").hide("slow");        }      //function onquerysucceeded(sender, args)     //{     //               //      alert("title: " + olist.get_title()));       //}     //function onqueryfailed(sender, args)     //{     //  alert("request failed");     //}   </script> 

if have in function alert, code works, add first line, sp.clientcontext() line in, breaks. nothing executes after , cant figure out why. appreciated.

thanks in advance!

you use sp.clientcontext on wrong way.

see complete basic operations using javascript library code in sharepoint 2013 , sp.clientcontext object on msdn

anyway can use clientcontext in 2 way:

  1. var clientcontext = sp.clientcontext.get_current(); getting current context if inside sharepoint page
  2. var clientcontext = new sp.clientcontext(siteurl); create new context arbitrary url

another tips wait until sp.js loaded

sp.sod.executefunc('sp.js', 'sp.clientcontext', sharepointready); 

see example on msdn page of second link or see sharepoint.stackexchange.com article


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -