You can read the selected value using the value
property of the select
tag. Try this:
function transfer() {
const originalNode = document.getElementById('original')
const resultNode = document.getElementById('result')
// Iterate over all the nodes within the original node
const resultFragment = document.createDocumentFragment()
originalNode.childNodes.forEach(cn => {
if (cn.nodeName === 'SELECT') {
// If the node is a 'select' tag, read its value as text
resultFragment.appendChild(document.createTextNode(cn.value))
} else {
// If the node is a text node (or anything else), copy it as-is
resultFragment.appendChild(cn.cloneNode(true))
}
})
// Reset the result node
resultNode.innerHTML = ""
// Set the result to the fragment created above
resultNode.appendChild(resultFragment)
}