I have choice value dropdown for priority with value - High, Normal, low. If Priority is "high" , Duedate= Current date + 2; If Priority is "Normal" , Duedate= Current date + 3; If Priority is "Low" , Duedate= Current date + 4;
I need to do this using javascript /Jquery as I am working on Sharepoint Online. I can't use Sharepoint designer or infopath.
This is the code I have written.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script type="text/javascript" src="//ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js"></script> <script> _spBodyOnLoadFunctionNames.push("dropdownvalue"); function dropdownvalue() { //add an onchange event to the dropdown var theSelect = getTagFromIdentifierAndTitle("select","DropDownChoice","Priority").onchange = function() {ChangeEvent()}; } function ChangeEvent() { var submittedDate= $("input[title='Submitted Date']").val(); //var submittedDate = new Date(ctx.CurrentItem.SubmittedDate); //get the dropdown var dropDown = getTagFromIdentifierAndTitle("select","DropDownChoice","Priority"); var dueDate = new Date(ctx.CurrentItem.DueDate); //get the selected value var priority= dropDown.options[dropDown.selectedIndex].text; var now = new Date(); //var nowPlus = new Date(); switch(priority) { case "High (<3 days)": dueDate.setDate(now.getDate()+2); break; case "Normal (3 days)": dueDate.setDate(now.getDate()+3); break; case "Low (>3 days)": dueDate.setDate(now.getDate()+4); break; default: date = null; } } </script>