I am trying to make a form, with a textbox next to a select box. When the user selects an option in the select I would like the textbox to display some text to explain what each select option means. I have this so far: (I have left out anything unrelated to the problem)

<script>
if(document.getElementById("list01").value=="burn")
	{
	document.getElementById("favorite").value="This burns their crops"
	}
if(document.getElementById("list01").value=="pillage")
	{
	document.getElementById("favorite").value="Kill women and children"
	}
if(document.getElementById("list01").value=="court")
	{
	document.getElementById("favorite").value=""
	}
</script>

<form id="myform" method="post">	how would you like to attack <? echo $attuser; ?>, you can:<br /><br />
<select id="list01" name="atk" class="but" onChange="explain(this)">
<option value="burn">burn crops</option>
<option value="pillage">pillage</option>
<option value="court">court women</option></select><input id="exp" value="" disabled="disabled" class="but" size="50" />
<input type="submit" name="attack" value="Attack!!" class="but" />
</form><br />

The above code doesnt work, could someone tell me where i have gone wrong please.
Thanks in advance for your any help

err.. You have using getElementById("favorite"), But, you have exp as the id for the textbox.

<html>
<head>
<script type="text/javascript">
function explain(value){
	if(document.getElementById("list01").value=="burn")
	{
		document.getElementById("exp").value="This burns their crops"
	}
	if(document.getElementById("list01").value=="pillage")
	{
		document.getElementById("exp").value="Kill women and children"
	}
	if(document.getElementById("list01").value=="court")
	{
		document.getElementById("exp").value="huh"
	}
}
</script>
</head>
<body>
<form id="myform" method="post">	how would you like to attack <? echo $attuser; ?>, you can:<br /><br />
<select id="list01" name="atk" class="but" onChange="explain(this)">
<option value="burn">burn crops</option>
<option value="pillage">pillage</option>
<option value="court">court women</option>
</select>
<input id="exp" value="" disabled="disabled" class="but" size="50" />
<input type="submit" name="attack" value="Attack!!" class="but" />
</form><br />
</body>
</html>

This works :)

help me out in struts how to fetch dynamically value in text box from select drop down option.

This question has already been answered. Start a new discussion instead.