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
Firefox, Chrome, Safari Have Grey Background For Mp4 Html5 Video
Any video (that I can make) with a white background becomes…
Red Border Still Appears On Inputs After Resetting An HTML 5 Form Firefox
I have an HTML 5 form! Great, I'm excited! I decide to …
Svg Animation And Firefox
I'm struggle with SVG animation drawing, which is work …
Form To Iframe Submission - How Do You Reset The Form After File Upload?
I have a form that submits the results to an iframe. The su…
How To Save Html5 Geolocation Data To Python Django Admin?
Is it possible to save the javascript html5 geolocation lat…
How To Hide/show Tabs Using Jquery
I have four tabs.On loading only the first tab is opened an…
How To Display A Python String As Html In Jupyter Notebook
In IPython notebook, I used to be able to display a python …
How To Limit The Html Table Records In Each Page
I am populating a table in my jsp which has more than 20 re…
How To Add Placeholder Field?
I've been trying to add placeholder in input type='…
Bounce Animation On A Scaled Object
What is the best way to have an object scale and then perfo…