Get value of Span Text

I have a span with class="span" and a hidden field class="dropdown".

The span text changes, and I need to grab the text and set it as the value of the hidden field's value.

I will then use php (I already have) and use the name of the hidden field to email me the text.

How do I do it?


Solution 1:

<script type="text/javascript">
document.getElementById('button1').onChange = function () {
    document.getElementById('hidden_field_id').value = document.getElementById('span_id').innerHTML;
}
</script>

Solution 2:

var span_Text = document.getElementById("span_Id").innerText;

console.log(span_Text)
<span id="span_Id">I am the Text </span>