0

Hello
Anyone can pls provide me with a sample code, whereby if I change a field value in a web form (from a drop-down list for example), the value shown in another field is automatically updated to show the needed value for that selected option?

2
Contributors
1
Reply
4
Views
6 Years
Discussion Span
Last Post by Shanti C
0

try this:
and change according to your requirement.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
function changeValue(x)
{
	var divEls = document.getElementsByTagName("div");
	var i = 0;
	
	for(i=0;i<divEls.length;i++)
	{
	divID=divEls[i].id;
	//alert(divID);
	//alert(x);
	if(divID == x)
		document.getElementById(divID).style.visibility = "visible";
	else
		document.getElementById(divID).style.visibility = "hidden";
	}
}
</script>
</head>
<body>
<select name="htmlcombo" id="htmlcombo" onChange="changeValue(this.value);">
 <option  value="0">Select</option>
    <option  value="1">Display Text1</option>
    <option  value="2">Display Text2</option>
    <option  value="3">Display Text3</option>
</select>

<div id="1" style="visibility:hidden" >hello1</div>
<div id="2" style="visibility:hidden">hello2</div>
<div id="3" style="visibility:hidden">hello3</div>
</body>
</html>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.