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.
<select id="materials" onchange="showChange()">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<br/>
<span id="material_display"></span>
<script>
function showChange(){
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
Three.js How To Cache (store Localy) 3d Models And Textures?
Im making a game with three.js and game levels are differen…
Fire An ASP.NET TextBox Event On Enter Press
How do i fire a ASP.NET click event when the user press ent…
Bug Reporter: Alternatives To GetDisplayMedia?
I am trying to implement a bug reporter on my website. My g…
Share Screen In Firefox Using RTCMultiConnection
I'm using RTCMultiConnection library in a project I'…
Split Comma Separated String By Comma
Need to split the string containing country names separated…
What's The Difference Between .clone() And .html()?
What is the difference between Jquery's .clone() and .h…
How To Map An Object Literal To Be An Instance Of My Constructor Function?
I have a constructor function like below: var Person = func…
Duplicate Image In Gallery
I have an image gallery that displays all the images inline…
How To Implement Auto Fixing A Div Like Https://www.yahoo.com
In Yahoo website, when scroll down, a blue part is fixed to…
Dropdown Menu On Refresh Changes Javascript
I have implemented a navbar uisng bootstrap 4,in which I ha…
December 2024
(1)
November 2024
(39)
October 2024
(67)
September 2024
(23)
August 2024
(385)
July 2024
(338)
June 2024
(713)
May 2024
(1302)
April 2024
(827)
March 2024
(1579)
February 2024
(1721)
January 2024
(1422)
December 2023
(1427)
November 2023
(450)
October 2023
(589)
September 2023
(286)
August 2023
(325)
July 2023
(256)
June 2023
(373)
May 2023
(224)
April 2023
(125)
March 2023
(150)
February 2023
(181)
January 2023
(266)
December 2022
(132)
November 2022
(238)
October 2022
(173)
September 2022
(163)
August 2022
(493)
July 2022
(305)
June 2022
(278)
Menu Halaman Statis
Beranda
© 2022 - JavaScript Programmer Calgary