0
4.4kviews
Write HTML Code to create a form containing dropdown list. This list contains colors red, green,blue and grey. Write a JavaScript code to change background color as user selected color option.
1 Answer
1
540views

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>
Please log in to add an answer.