I'm trying to change dynamically the text of a span based on the the option that got selected. PS: I'm using Django + Python to generate options Here is my code :
Solution 1:
It's innerText, not innerTEXT and the id of your span is not closed properly; you only have one quotation mark to the left of the id and are missing the quotation mark to the right of the id.You also need to attach your function to an Event Handler like onchange for your select.<selectid="materials"onchange="showChange()"><optionvalue="1">1</option><optionvalue="2">2</option><optionvalue="3">3</option></select><br/><spanid="material_display"></span><script>functionshowChange(){
var selected_material = document.getElementById("materials").value;
document.getElementById("material_display").innerText = selected_material;
}
</script>Copy
Share
Post a Comment
for "Dynamically Change Span Text Based On Selected Option Javascript"
Top Question
Right Floated Element Disappears When Using Columns In Firefox
I am using an ol element with column-count and column-gap p…
Remove The Button Inside The Dropdownlist
Is there a way to hide or remove the arrow button inside a …
Adding Asterisk To Placeholder, Or A Nice Way To Mark Required Fields Via Placeholder
I'm looking for a way to style the asterisk in the plac…
Mystery Margin Or Padding On List
I cannot figure out where the padding is coming from the on…
Homepage Slow To Load
When I go to the homepage of my website after clearing my c…
How To Add Placeholder Field?
I've been trying to add placeholder in input type='…
Continuous Image Swap While Mouse Is Hovering
i have an idea but i'm not quite sure how to execute it…
3 Columns + 100% Height
I need same as in the http://blog.html.it/layoutgala/Layout…
Escaping & > Characters In Ng-bind In AngularJs
I have a use case, where we can have '&' and &#…
Align Div Element To Bottom Of Container
I am trying to bottom align one of three divs inside a cont…