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

Recommended Answers

All 6 Replies

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 :)

thanks naveen, once again you have solved my problem :)

You are welcome :)

Nevermind! I got it! thank you! :)

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

i want this dynamically in struts

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.