Reputation: 1
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
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