0

enter image description hereI have the input type as text for the date field and I am confused how to store the same in a variable and on change of that date function need to populate other column values SharePoint list. I need to populate values based on two field changes in SharePoint list. i.e on selection of both field certain fields should populate. Can anyone help me with this?

4
  • The input value can be got with Jquery: var test=$("input[title='Date']").val(); And what is your requirement to populate value based on two fields change, did you want populate other column control in the new form once the date changed ?
    – Jerry
    Commented Sep 11, 2018 at 9:59
  • Yes and also I need to combine meaning on change of date and one more column other fields should populate. like for example. on change of col A and col B The col C, Col D , Col E should be updated. These get updated based on the ajax call which is calling the rest api. Commented Sep 11, 2018 at 12:42
  • Add rest api code in DatePickerChanged function below, I think it will meet your requirement.
    – Jerry
    Commented Sep 11, 2018 at 13:28
  • I need to store one more value in a variable and use both values in the variable as input to the api. I am using the (.change(function()). I am confused how to use two functions in one? Can you please help me Commented Sep 11, 2018 at 13:30

1 Answer 1

2

The input value can be got with Jquery:

var test=$("input[title='Date']").val();

And you could trace the value change for this date field control in the new form like this:

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript">
$(document).ready(function() {
  $('input[title="Date"]').get(0).onvaluesetfrompicker=DatePickerChanged;    
});

function DatePickerChanged() {
    // Do stuff

    alert("value changed");
}
</script>

Write your populate logic code in DatePickerChanged function.

12
  • I need to store one more value in a variable and use both values in the variable as input to the api. I am using the (.change(function()). I am confused how to use two functions in one? Commented Sep 11, 2018 at 14:53
  • 1
    Per my test, .change() function won't trace the Date Control change event in SharePoint, you will need onvaluesetfrompicker like above. Have you tested my code above in SP List form?
    – Jerry
    Commented Sep 11, 2018 at 15:00
  • 1
    You can store the date control value like I said above var test=$("input[title='Date']").val();, define a global variable in your code beginning.
    – Jerry
    Commented Sep 11, 2018 at 15:17
  • 1
    Convert like this: var date = "03-11-2014"; var newdate = date.split("-").reverse().join("-");
    – Jerry
    Commented Sep 11, 2018 at 15:24
  • 1
    var date="9/11/2018"; var newdate = date.split("/");var year=newdate[2];var day=newdate[1];var month=newdate[0]; var final=year+"-"+month+"-"+day;
    – Jerry
    Commented Sep 12, 2018 at 2:59

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.