Article Introduction: sets the background color according to the options. |
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> "JavaScript daily Practice"-set background color based on options </title>
<script type= "Text/javascript" >
function SetProperty ()
{
var content = document.getElementById ("content");
var sel = document.getElementById ("Selectcolor");
var propertyvalue = Sel.options[sel.selectedindex].value;
content.style["background"] = PropertyValue;
}
</script>
<body>
<div id= "Content" >
<p> Select color and click the button "Set background color". </p>
<select id= "Selectcolor" >
<option value= "Aqua" >aqua</option>
<option value= "BLACK" >black</option>
<option value= "Blue" >blue</option>
<option value= "Fuchsia" >fuchsia</option>
<option value= "Gray" >gray</option>
<option value= "Green" >green</option>
<option value= "Lime" >lime</option>
<option value= "Maroon" >maroon</option>
<option value= "Navy" >navy</option>
<option value= "Olive" >olive</option>
<option value= "Purple" >purple</option>
<option value= "Red" >red</option>
<option value= "Silver" >silver</option>
<option value= "Teal" >teal</option>
<option value= "White" >white</option>
<option value= "Yellow" >yellow</option>
</select>
<button onclick= "SetProperty (); return false; > Set Background color </button>
<br/>
<br/>
</div>
</body>
Writing this today wasted a lot of my time, it was a very simple small code but I just can't write the effect. Finally under the Barina I seek the help of the sunylost God, in the language.
I hope you will avoid the previous error code.
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> "JavaScript daily Practice"-set background color based on options </title>
<script type= "Text/javascript" >
var content = document.getElementById ("content");
function SetProperty ()
{
var sel = document.getElementById ("Selectcolor");
var propertyvalue = Sel.options[sel.selectedindex].value;
content.style["background"] = PropertyValue;
}
</script>
<body>
<div id= "Content" >
<p> Select color and click the button "Set background color". </p>
<select id= "Selectcolor" >
<option value= "Aqua" >aqua</option>
<option value= "BLACK" >black</option>
<option value= "Blue" >blue</option>
<option value= "Fuchsia" >fuchsia</option>
<option value= "Gray" >gray</option>
<option value= "Green" >green</option>
<option value= "Lime" >lime</option>
<option value= "Maroon" >maroon</option>
<option value= "Navy" >navy</option>
<option value= "Olive" >olive</option>
<option value= "Purple" >purple</option>
<option value= "Red" >red</option>
<option value= "Silver" >silver</option>
<option value= "Teal" >teal</option>
<option value= "White" >white</option>
<option value= "Yellow" >yellow</option>
</select>
<button onclick= "SetProperty (); return false; > Set Background color </button>
<br/>
<br/>
</div>
</body>