We are using local storage to hold a text box/title value from a 'main' problem list. In this 'main' list, we first identify the issue/problem. We then add tasks in a task list associated to the 'main' problem list identified above.

We are running into a roadblock of trying to use localStorage to populate a choice field in the task list. We can hard code the value, and have the task's choice field get populated/selected properly. If we use a localStorage variable/value, the choice field will not populate/select properly. Below code shows where we have "test 2 Option" hard coded, and this works properly. If we used the line right below (currently commented out) with localStorage, nothing happens on the choice dropdown. The alert tells us we have localStorage correctly, and in Chrome + Inspect / Resources / Local Storage, I can see the Key & Value pair successfully:

$(function() {
var selectedText = "test 2 Option";

$('#Problem_myLIST84dfa1dccc5b_\\$LookupField option').map(function () {
    if ($(this).text() == selectedText) return this;
}).attr('selected', 'selected');

Please advise...thank you!


1 Answer 1


I got this scenario to work with SPUtility.js ...which is a bit cleaner and easier to use than grabbing the ID of the control needing to be populated like:

Problem_myLIST84dfa1dccc5b_\$LookupField option

I have a choice column call ddlTest. When testing the code that used SPUtility, the Chrome console was showing me a lot of padding existed in the localStorage variable. Once I used $.trim(), the code was working to populate the choice value:

var selectedText = $.trim(localStorage.getItem("lclstrgTaskTitle"));

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.