Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

show combo box if field = x else show text box

Status
Not open for further replies.

evr72

MIS
Dec 8, 2009
265
US
Hello,

I am very new and to JavaScript, was wondering if anybody could point me in the right direction.

I am trying to build a script to show a combo box if a field value = 1 and a text box if the field value = to 0

not sure if I can do this any help is much appreciated.
 
Code:
<!DOCTYPE HTML>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>test page</title>

<script type="text/javascript">
function init(){
	document.getElementById('myInput1').addEventListener('blur', monitorChange);
	//set initial state
	monitorChange();
}

function monitorChange(){
	var i1 = document.getElementById('myInput1');
	if(i1.value == 'somevalue'){
		document.getElementById('mySelect').style.display = 'none'; //hide select box
		document.getElementById('myInput2').style.display = 'inline'; //show text box
	} else {
		document.getElementById('mySelect').style.display = 'inline'; //show select box
		document.getElementById('myInput2').style.display = 'none'; //hide text box
	}
}

</script>


</head>

<body onload="init();">

<form id="myform"  action="##">

<!-- start -->
Text: <input name="myInput" value="" type="text" id="myInput1"/><br/>

<select name="mySelect" id="mySelect" style="display:none">
<option value="">...</option>
</select>
<input name="myInput2" id="myInput2" style="display:none" />

</form>

</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top