NealR
NealR

Reputation: 10669

jquery event.preventDefault() issues with IE 8

In my jquery autocomplete select function, I need to use the event.preventDefault() method to prevent the default ui.item.value from populating the input text box the autocomplete is wired too. This works great in Chrome, however in IE 8 (which is in use by a majority of our users) the .preventDefault() line throws the following error:

Unexpected call to method or property access

Here is the jQuery for good measure. Does anyone know of a work-around for this method in IE 8?

var tempResults = [];
$(function () {
    $('#DRMCompanyName').autocomplete({
        source: function (request, response) {
            $.ajax({
                url: '@Url.Action("compSearchByName", "AgentTransmission")',
                type: 'GET',
                dataType: 'json',
                data: request,
                success: function (data) {
                    tempResults = data;
                    response($.map(data, function (value, key) {
                        return {
                            label: value + " " + key, 
                            value: key
                        };
                    }));
                },
            });
        },
        minLength: 2,
        select: function (event, ui) {
            event.preventDefault(); // <-Causing a problem in IE 8...
            $('#DRMCompanyName').val(tempResults[ui.item.value]);
            $('#DRMCompanyName').text(tempResults[ui.item.value]);

            if ($('#DRMCompanyId').text() == '') {
                $('#DRMCompanyId').val(ui.item.value);
                $('#DRMCompanyId').text(ui.item.value);
            }
        }
    });
});

Upvotes: 0

Views: 1597

Answers (1)

A. Wolff
A. Wolff

Reputation: 74420

You could use return false instead but as i said in comment: return false = event.preventDefault() + event.stopPropagation() But in your case, should fit your needs.

Upvotes: 1

Related Questions