Leon2110,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<script>
document.addEventListener( "DOMContentLoaded" , function() {
zadanie.addEventListener("change", function(event) {
for (var parent, txt, node, temp = [], textNodes = document.createTreeWalker(this, NodeFilter.SHOW_TEXT, null, false); node = textNodes.nextNode();) {
txt = node.nodeValue.trim();
parent = node.parentNode;
if(parent == this || parent.selected) txt && temp.push(txt);
}
ans1.value = temp.join(" ")
})
});
</script>
</head>
<body>
<h2 id="zadanie">
John is
<select class="input" >
<option>a</option>
<option>an</option>
<option>are</option>
</select>
honest person</h2>
<input name="ans1" id="ans1" value="">
</body>
</html>