0

I need Jquery to set a text field to the selection made in a choice field and add a date time stamp .

Example 1: Choice1: selected option = Blue

Result in TextField: mm/dd/yyyy: Choice1 changed to Blue

Ideal Wish: Choice1: selected option = Blue

Result in TextField: "mm/dd/yyyy: Choice1 changed to Blue by [user]

Thank you!

1
  • Why not use OOB Version feature? list settings->Versioning Settings
    – Lee_MSFT
    Apr 8 '20 at 3:31
0

You can use the below code which gives output like based on choice selection updates the description column - it uses sp service and jquery.

<script src="/Shared%20Documents/jquery-1.7.2.js" type="text/javascript"></script>
    <script type="text/javascript">


    $(document).ready(function() {
   $("select").change(function() {



     var selectedValue = this.value;

             $().SPServices({
            operation: "GetListItems",
        async: false,
       listName: "CoolCities",
       CAMLViewFields:     "<ViewFields><FieldRef Name='Description' /></ViewFields>",
     CAMLQuery: "<Query><Where><Eq><FieldRef Name='City'/><Value Type='Text'>" + selectedValue + "</Value></Eq></Where></Query>",
CAMLRowLimit: 1,
    completefunc: function (xData, Status) {
      $(xData.responseXML).SPFilterNode("z:row").each(function() {
        var liHtml = $(this).attr("ows_Description");
        alert(liHtml);
 $("input[title='Description1']").val(liHtml);
    });
    }
  });
});

});</script>

Note : In the the above code, create a variable and construct a string as per your need like date and value in the choice by user name - then pass that variable (replace liHtml) in . val(your variable)

For details steps refer to the below article :

Using SPServices to Query a list in SharePoint 2010

Approach 2:

We can implement the above using the simple SharePoint designer list level workflow, just need to construct a string as per your need and using the update field value action, we can update text column value based choice selection.

3
  • So, please explain what this is doing. Is it copying the name of a city from Choice field to a description field? I am not sure how to plug-in the field names I used above into this code. Thanks.
    – ChasEpes
    Apr 8 '20 at 1:29
  • It's not copying the city name to description field, it is, based on the city selection changes in ddl, it updates the value in the description field.. please read the support article mentioned above, it is explained. Thanks Apr 8 '20 at 1:38
  • I read the article but this does not answer my original question. Thanks, I need to copy the selection in a Choice field to a text field in the same list.
    – ChasEpes
    Apr 8 '20 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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