0

I am sending a query string into NewForm.aspx. I have populated a drop down with that value. Everything works great in Chrome but Internet Explorer does not save the pre-populated value. The value is actually populated on the dropdown list but if I click save, IE acts as if no option was selected. The values I expect do show up in the console. What can I do to make IE recognize that a value has been selected?

$(document).ready(function() {

var queryStringVals = $().SPServices.SPGetQueryString();
var supplierID = queryStringVals["SupplierID"];
console.log(supplierID);

$().SPServices.SPComplexToSimpleDropdown({
    columnName: "SupplierID",
});

//like :contains but only selects exact matches
$.expr[':'].textEquals = function(a, i, m) {
    return $(a).text().match("^" + m[3] + "$");
};

var selectedSupplierID = $("option:textEquals('" + supplierID + "')").val();
$("select[title=SupplierID]").val(selectedSupplierID);

//No change
//$("select[title=SupplierID]").val(selectedSupplierID).trigger("click");

console.log($("select[title=SupplierID]").val());

//Nope, sigh
//$("option:contains('" + supplierID + "')").attr("selected", "selected");


//tried this before SPComplexToSimpleDropdown
//$("option:textEquals('" + supplierID + "')").val().next("img").trigger("click");

});

1 Answer 1

2

I needed to add this line to the end:

$("select[title=SupplierID]").change();

Full code is as follows:

    $(document).ready(function() {

        var queryStringVals = $().SPServices.SPGetQueryString();
        var supplierID = queryStringVals["SupplierID"];

        $().SPServices.SPComplexToSimpleDropdown({
            columnName: "SupplierID",
        });

        //like :contains but only selects exact matches
        $.expr[':'].textEquals = function(a, i, m) {
            return $(a).text().match("^" + m[3] + "$");
        };

        var selectedSupplierID = $("option:textEquals('" + supplierID + "')").val();
        $("select[title=SupplierID]").val(selectedSupplierID);
        $("select[title=SupplierID]").change(); 

    });

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.