Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8451111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:08:58+00:00 2026-06-10T11:08:58+00:00

I was looking for help last week to get a simple javascript code made

  • 0

I was looking for help last week to get a simple javascript code made for SharePoint 2007 working for SharePoint 2010 and didn’t really get a clear answer that i could use where i work unfortunately so i decided to try to just make my own. It’s suppossed to be an Auction List and have a countdown in the “Time Left” field till the item expires, but i can’t figure out what’s wrong. I am very unfamiliar with javascript and sharepoint but i am an experienced programmer. Can anyone help with this? Here’s the code below:

<script type="text/javascript">
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var lists = web.get_lists();
var listId = SP.ListOperation.Selection.getSelectedList();
var list = lists.getById(listId);
var item = getItemByName("End Date");
var end = Date.parse(item.text())/1000;
var todayNow = new Date();
todayNow = Date.parse(today)/1000;
var result = (end-todayNow);
var item2 = getItemByName("Time Left");
item2.text(result);
</script>

The End Date is a field that will probably be hidden, but just used as a placeholder to find the difference from now till the item expires.

Thanks guys for any responses.

Edit: Ok thanks Robert, you’ve really helped a lot. I was just about to post this when i saw your last comment. I’m extremely close now since I’ve been googling and researching what you said in your first comment and I’ve gotten this far:

<

script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(getWebSiteData, "sp.js");
var context = null;
var web = null;
var lists = null;
var listId = null;
var list = null;
var item = null;
function getWebSiteData(){
context = new SP.ClientContext.get_current();
web = context.get_web();
lists = web.get_lists();
listId = SP.ListOperation.Selection.getSelectedList();
list = lists.getById(listId);
context.load(list, 'End Date');
context.executeQueryAsync(Function.createDelegate
(this, this.onSuccessMethod), Function.createDelegate
(this, this.onFailureMethod));
}
function onSuccessMethod(sender, args){
alert('web title:' + web.get_title() + '\n ID:' + web.get_id
());
}
function onFailureMethod(sender, args){
alert('request failed' + args.get_message
() + '\n' + args.get_stackTrace());
}
</script>

I think the only thing i have left to do is figure out how to get the current item so i can set the Time Left for that specific item. Do you know how to do that? Am i as close as i think?
Thanks again for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:08:59+00:00Added an answer on June 10, 2026 at 11:08 am

    When you use javascript to access SharePoint, you’re using the ECMA Client Object Model. I haven’t worked with the Client Object Model for 07, but I have for ’10, and right away can tell the code you posted won’t work in sp10. At least in sp10 com, every time you grab a new instance of a SharePoint object (list, web, listItem, column, etc), you need to set that item into your local context, then load the context against the server via an asynchronous method. Only after that point, can you access the fields in the referenced object that you desire. Let me know if you cna’t figure it out. Here’s some sample code: http://pastebin.com/3amgaEhv

    edit:
    As for updating list items, I just found this link, here: http://sprider.org/2011/12/13/sharepoint-ecmascript-to-adddeleteupdateget-list-items/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have spent the last two days looking for a simple javascript or jquery
Looking for some help! I need to split a string at the last occurrence
I'm looking to help users of some of my templated code by using BOOST_STATIC_ASSERT
I need some help with rally. I'm currently looking at creating a simple app
Looking for help creating a script that will replace the last line of an
I am looking for help with the database scheme, not the actual cloud itself.
I am looking for help in determining if the class model that I am
I'm looking for help with my query below. which is never returning anything for
I'm looking for help using sum() in my SQL query: SELECT links.id, count(DISTINCT stats.id)
I'm looking for help to create a query, to solve the following problem: Let's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.