Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 496
Hunter Mitchell Avatar asked Apr 27 '12 02:04

Hunter Mitchell


People also ask

How do you find the value of text in span?

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.

Can spans have values?

a span doesn't have a value attribute.

Does span have value attribute?

Default value of HTML span attribute is 1.


1 Answers

<script type="text/javascript"> document.getElementById('button1').onChange = function () {     document.getElementById('hidden_field_id').value = document.getElementById('span_id').innerHTML; } </script> 
like image 98
John Conde Avatar answered Oct 02 '22 16:10

John Conde