0

i have the following code:

window.onload = function () {
    var setTime = /*this should go the number*/
    var fiveMinutes = 60 * setTime;
        display = document.querySelector('#timer2');
    startTimer(fiveMinutes, display);
};

what i want is var setTime to get the value or retrieve from list with column named testval the datatype for testval is number thanks all!

2
  • pls give us html code, where testval is Commented Nov 20, 2015 at 10:26
  • testval is a field in list it has a value of 15. i want setTime to be 15! Commented Nov 20, 2015 at 10:31

2 Answers 2

2

To communicate with SharePoint you need to use the JavaScript client object model as follows:

 var ctx = new SP.ClientContext.get_current();
 var web = ctx.get_web();
 var listCollection = web.get_lists();
 var list = listCollection.getByTitle(NameOfYourList);
 var listItem = list.getItemById(TheItemID);
 context.load(listItem);

 context.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

and then

 function onQuerySucceeded() {
 var setTime =  listItem.get_item('testval');
 //continue your work
}

 function onQueryFailed(sender, args) {
 alert('failed');
}

Remember to reference SP.js script tag:

 <SharePoint:ScriptLink Name="SP.js" runat="server" OnDemand="true" Localizable="false" ></SharePoint:ScriptLink>
Sign up to request clarification or add additional context in comments.

1 Comment

Glad to help. you can accept answer if it works please.
2

if it's a td elem like this <td name="testval">15</td>:

window.onload = function () {
   var testval = document.getElementsByName('testval')[0]; // if it's the first elem with this name
   //var testval = $('td[name=testval]'); // jquery
   var setTime = parseInt(testval.innerHTML); // 15
   var fiveMinutes = 60 * setTime;

   display = document.querySelector('#timer2');
   startTimer(fiveMinutes, display);
};

jsFiddle for you - http://jsfiddle.net/y02os529/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.