I have a form using rows to receive user input. The user can click a link to get a new row. The link calls a function that, after creating a new row and cell, creates a new element. When the element is created another function is called that, when needed, uses AJAX to receive the SELECT options. This works fine.
When the new element is complete, a function is called to copy selected element values from the previous row into the new row. However, what happens is beyond me.
Copying an INPUT value from the previous row to the new row works. Copying the selectedIndex from a SELECT only works when an alert box is shown before new_element.selectedIndex is set.
The function:
function CopyPreviousValue(new_element, old_element_name, new_id) {
if (new_id > 1) {
var old_element = document.getElementsByName(old_element_name)[0];
switch (old_element.tagName) {
case "SELECT":
//alert("[old_element.selectedIndex] "+old_element.selectedIndex);
new_element.selectedIndex = old_element.selectedIndex;
if (old_element.selectedIndex != -1) new_element.disabled = false;
break;
case "INPUT":
new_element.value = old_element.value;
if (old_element.value != "") new_element.disabled = false;
break;
}
}
}
I can't see anything spectacular here.. Can someone please enlighten me on why this happens and how to fix this?