Surya
Surya

Reputation: 1

Error: Object doesn't support this property or method working in chrome not working in IE

When i am trying to move elements from listA to List B , getting "Error: Object doesn't support this property or method" but working fine in chrome. Getting error at bold line.

function moveAllRight()
{
var left = document.getElementById('listA');
var right = document.getElementById('listB');

var i=left.options.length;
    if(i>0){
        while(i >=0){
            right[i]=left[i]; // <-- error
            i--;
        }
    }
}

Upvotes: 0

Views: 569

Answers (1)

Felix Kling
Felix Kling

Reputation: 816810

It appears left and right are <select> elements. If Internet Explorer doesn't allow you set options this way, then you should use the standard DOM API to add and remove the properties.

See the MDN documentation.

You could do:

// Remove existing options
while (right.options.length) {
  right.remove(0);
}

// Copy existing options
for (var i = 0, l = left.options.length; i < l; i++) {
  right.add(left.options[i].cloneNode(true));
}

Upvotes: 2

Related Questions