Event onChange execute JavaScript when user selects the option of a <select>
element and set the background color based on selected color option.
Program :
<!DOCTYPE html>
<html>
<header>
<title>Background Color Selector</title>
</header>
<form name="bgcolorForm">
<center>
<h1>Select Background Color:</h1><br><br>
<select onChange="if(this.selectedIndex!=0)
document.bgColor=this.options[this.selectedIndex].value">
<option value="0" selected></option>
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
<option value="grey">Grey</option>
</select>
</center>
</form>
</html>