Animations

API

Arrays

Async

Basics

Challenges

Classes

Console

Dates

Debugging

DOM Elements

DOM Methods

DOM Navigation

DOM Properties

Event Listeners

Flow Control

Forms

Functions

Global Functions

JSON

Keywords

Libraries (3rd party)

Math

Modules

Objects

Snippets

String

Types

Widgets

Window Object

JavaScript - OnChange

change is easy and is often used in form controls.


Syntax


// In HTML:
<element onchange="myScript"></element>

// In JavaScript:
object.onchange = function(){myScript};

// In JavaScript, using the addEventListener() method:
object.addEventListener("change", myScript);



function ShowColor()
{
    let colorList = document.getElementById("ColorList");
    let color = colorList.options[colorList.selectedIndex].text; //.value would get you the value and not the text

    let demo1 = document.getElementById("demo1");
    demo1.innerHTML = color;
}