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?
Use the textContent property to get the text of a span element, e.g. const text = span. textContent . The textContent property will return the text content of the span and its descendants.
a span doesn't have a value attribute.
Default value of HTML span attribute is 1.
<script type="text/javascript"> document.getElementById('button1').onChange = function () { document.getElementById('hidden_field_id').value = document.getElementById('span_id').innerHTML; } </script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With