1,105,447 Community Members

change background color using the selected value from combo box

Member Avatar
thebluestar
Junior Poster in Training
55 posts since Apr 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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!

Member Avatar
JugglerDrummer
Junior Poster
138 posts since Apr 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 22 [?]
Skill Endorsements: 0 [?]
 
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
Member Avatar
thebluestar
Junior Poster in Training
55 posts since Apr 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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