1

we have a list for travel schedules. We have a dropdown for Monday to Friday then individual mulitselects for each day. i am trying to use the following code to auto populate the selected item for each day.

    $(document).ready(function(){
$("#Monday_x0020__x002d__x0020_Frida_1922e8b2-788e-47ee-a1f8-5920062dd680_\\$LookupField").change(function(){

    var fill= $('#Monday_x0020__x002d__x0020_Frida_1922e8b2-788e-47ee-a1f8-5920062dd680_\\$LookupField option:selected').val();
    alert(fill);
    var dTitle = $('#Monday_x0020__x002d__x0020_Frida_1922e8b2-788e-47ee-a1f8-5920062dd680_\\$LookupField option:selected').text();
    var dest = ('<option value="'+fill+'" title="'+dTitle+'">'+dTitle+'</option><option></option>');
$("#Monday_x0020_Travel_554556e8-f378-446a-810d-4855c469063c_SelectResult").append(dest);
$("#Tuesday_x0020_Travel_c9b9e6dc-4f15-4245-8fb0-2d115a29e003_SelectResult").append(dest);
$("#Wednesday_x0020_Travel_fa63a385-3ad5-4e22-8f8a-f3a20728d3d1_SelectResult").append(dest);
$("#Thursday_x0020_Travel_a6273f84-02a8-49d7-a35a-589cc339b99c_SelectResult").append(dest);
$("#Friday_x0020_Travel_be9b803a-bb53-4cb5-bb77-ad17b9d5c803_SelectResult").append(dest);

});
});

the code works for populating the "Selected Values" boxes but when I post the form the values do not post. If I use ie dev tools and refresh the dom after auto populating the fields they show up in dev tools but still do not post.

Oddly if I add another selection to a day (as they are multiple select boxes) both values will then be posted.

I put the code into a Context Editor in the default new form. jquery is being loaded I just left out those calls here.

we are on SharePoint 2010

Any Ideas?? Thanks

4 Answers 4

1

There are hidden fields that hold the actual value of the fields in the list.

In dev tools, $("[id$='MultiLookup']").val() returned the value "2|tTest2|t3|tTest3" for

<option value="2" title="Test2">Test2</option>  
<option value="3" title="Test3">Test3</option>

Reference: http://weblogs.asp.net/bsimser/defaulting-values-in-a-multi-lookup-form-in-sharepoint

1
  • That was it. I just added values to that hidden field and it worked. The selected values from the auto fill now save to the list.
    – KurtH
    Jun 11, 2015 at 12:34
0

I think you're missing a $:

var dest = $('<option value="'+fill+'" title="'+dTitle+'">'+dTitle+'</option><option></option>');

Why not clone the selected option and then append to the other selects?

$(document).ready(function()
{
    $("#Monday_x0020__x002d__x0020_Frida_1922e8b2-788e-47ee-a1f8-5920062dd680_\\$LookupField").change(function()
    {
        var selected = $(this).find("option:selected");
        alert(selected.val());

        $("#Monday_x0020_Travel_554556e8-f378-446a-810d-4855c469063c_SelectResult").append(selected.clone());
        $("#Tuesday_x0020_Travel_c9b9e6dc-4f15-4245-8fb0-2d115a29e003_SelectResult").append(selected.clone());
        $("#Wednesday_x0020_Travel_fa63a385-3ad5-4e22-8f8a-f3a20728d3d1_SelectResult").append(selected.clone());
        $("#Thursday_x0020_Travel_a6273f84-02a8-49d7-a35a-589cc339b99c_SelectResult").append(selected.clone());
        $("#Friday_x0020_Travel_be9b803a-bb53-4cb5-bb77-ad17b9d5c803_SelectResult").append(selected.clone());
    });
});
2
  • Same result. The fields are filled in but they don't post through.
    – KurtH
    Jun 10, 2015 at 19:32
  • When you say "posted" you mean not saved to the list, right? Anyway we could get a few screenshots to help us visual people? Jun 10, 2015 at 20:26
0

You need to add the selected attribute to the option element:

var dest = ('<option selected value="'+fill+'" title="'+dTitle+'">'+dTitle+'</option><option></option>');
1
  • Should have mentioned I already tried that both selected and selected="selected". Neither worked.
    – KurtH
    Jun 10, 2015 at 19:38
0

A lot of people are saying the fields are set but they don't post when saved. That's because you need to set the related hidden field. I posted a solution here:

set multiselect lookup column using jquery

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.