1.11M Members

change background color using the selected value from combo box

 
0
 
<html>
<head>
 	<title>Nhung rac roi ko hieu</title>
	<script type="text/javascript">
			function getvalue(list)
			{
			     while(list.options.length) list.options[list.selectedIndex].value=null;
			     var value = list.options[list.selectedIndex].value;
			     document.write(value);
			     document.bgColor = value;
			}
	</script>
</head>
<body bgColor="lavender">
		Here is the list for you to Change the bgColor!
		<br/>
		<select name="list1" onchange="getvalue(this)">
				<option value="green">Green</option>
				<option value="orange">Orange</option>
				<option value="yellow">Yellow</option>
				<option value="pink">Pink</option>
		</select>
</body>
</html>

Here is my code , it works but how can I do to remain the list each time click one option . I mean when I click one option the background changes, also the combo box is remainded to try the next option!
Please help me clarify the problem. Thanks!

 
1
 

you set the value to null then read it? Why are you using "while(list.options.length)"?

try this:

function getvalue(list)
{
document.getElementsByTagName("body")[0].bgColor=list.value;
}
Question Answered as of 4 Years Ago by JugglerDrummer
 
0
 

you set the value to null then read it? Why are you using "while(list.options.length)"?

try this:

function getvalue(list)
{
document.getElementsByTagName("body")[0].bgColor=list.value;
}

Ok, ^^.Thank you very much!

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article