Question: 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.
0

Subject: Internet Programming

Topic: Client Side Programming: HTML, CSS and JavaScript

Difficulty: Medium

ADD COMMENTlink
modified 14 months ago  • written 15 months ago by gravatar for Binita Mayekar Binita Mayekar40
0

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>
ADD COMMENTlink
written 15 months ago by gravatar for Binita Mayekar Binita Mayekar40
Please log in to add an answer.