Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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");

});
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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(); 

    });
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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