<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!

Recommended Answers

All 2 Replies

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;
}

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.