I 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?
-
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 ?– JerryCommented 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.– Prashanth EdigeCommented Sep 11, 2018 at 12:42
-
Add rest api code in DatePickerChanged function below, I think it will meet your requirement.– JerryCommented 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– Prashanth EdigeCommented Sep 11, 2018 at 13:30
Add a comment
|
1 Answer
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.
-
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
-
1Per 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?– JerryCommented Sep 11, 2018 at 15:00
-
1You can store the date control value like I said above var test=$("input[title='Date']").val();, define a global variable in your code beginning.– JerryCommented Sep 11, 2018 at 15:17
-
1Convert like this: var date = "03-11-2014"; var newdate = date.split("-").reverse().join("-");– JerryCommented Sep 11, 2018 at 15:24
-
1var 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;– JerryCommented Sep 12, 2018 at 2:59