javascript - How to change content of a span based on Drop down selection -
I have a label with a selection box and a span, I want to change the span content because users drop them Change the selection down box
& lt; Select class = "text_select" id = "field_6" name = "field_6" & gt; & Lt; Option value = "- select -" & gt; - Select - & lt; / Options & gt; & Lt; Option value = "option one" & gt; Option A & lt; / Options & gt; & Lt; Option value = "option two" & gt; Option two & lt; / Options & gt; & Lt; Option value = "option three" & gt; Option Three & lt; / Options & gt; & Lt; / Select & gt; & Lt; Label class = "form_field" & gt; Your selected & lt; Span id = "aggregator_name" & gt; & Lt; / Span & gt; & Lt; / Label & gt; I am using this script
This is the problem, whenever I refresh the page, instead of the span it changes with "- select", but when I change the dropdown to the second option, this span Does not the content change? Please help people
You will need to call your function with the change of drop-down: < Previous> document.getElementById ("field_6"). Onchange = notEmpty; Demo:
Or, since you have used the "jquery" tag, all your JSs have the following place:
$ (document) .ready (function () {$ ("# field_6"). Change (function () {$ ('# aggregator_name') .HTML ($ (this) .val ());}) . ();}); Demo:
(Note: If the above script is included in the block that appears after the "field 6" element, for example, if your script ends In the body, you do not need to wrap the code in the document-ready handler.)
Comments
Post a Comment