3

My goal is to pull a value on the EditForm from a Date field. I want to take the 'due date' field, do a "get date", and subtract the difference between that date and today to get a "days left" number. I don't think the last part will be difficult since I'm fairly familiar with javascript, but the getFieldValue with the four parameters method isn't returning anything. Is there a better method to choose?

Well, I tried....

var myDate = //
alert(myDate)

......but that won't work because it's not a single line of text.

I tried:

var theDate = getFieldValue('Due Date','','; ','');
alert(theDate);
4
  • Can you post some of the code that you've tried, it will help us debug it Commented Feb 14, 2014 at 20:57
  • done "Due Date" is the name of my date column by the way. Commented Feb 14, 2014 at 21:48
  • is "alert(Due Date);" a typo -- did you mean "alert(colDate)"?; also, can you post an HTML snippet (portion of tags near and including the input) Commented Feb 14, 2014 at 21:56
  • Yes, that was a typo. Sorry! The only html I have are the two references to jquery and spservices files and everything enclosed in the html and script tags. Should I have more? @udog Commented Feb 15, 2014 at 2:19

1 Answer 1

6

I'm not sure that I understand your difficulty. I used your jQuery above in the following way:

<input type="text" 
       value="2/21/2014" 
       maxlength="45" 
       id="DueDate_42f25f08-a9dc-4559-aded-a2e2b9ec5e13_$DateTimeFieldDate" 
       title="Due Date" 
       class="ms-input" autopostback="0">

//I typed this into the console. I use Moment.js for most of my date-time work.
var myDate = new Date( $("input[title='Due Date']").val());
var timeLeft = moment(myDate).fromNow();
console.log("This item is due " + timeLeft + ".");

And got this:

enter image description here

Injected into my page via

var myDate = new Date( $("input[title='Due Date']").val());
var timeLeft = moment(myDate).fromNow();
$("#time-left").text("This item is due " + timeLeft + ".");

enter image description here

So your code should work just fine!

1
  • Ah my issue was that I was retrieving the date value incorrectly. Thank you for your help! Commented Feb 17, 2014 at 17:20

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.