faqts : Computers : Programming : Languages : JavaScript : Forms

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

27 of 116 people (23%) answered Yes
Recently 3 of 10 people (30%) answered Yes

Entry

How to show or hide a select box depending on the options selected in another select box?

Aug 11th, 2006 16:11
David Alden, sanjeev kulkarni,


<html>
<script type="text/javascript" language="javascript">
	function changeSelectBox(){
		var changedValue=document.thisForm.thisSelect.value;
		if(changedValue == 1){
			document.thisForm.secondSelect.disabled=true;
		} else if(changedValue == 2){
			document.thisForm.secondSelect.disabled=false;
		}
	}
</script>
	<form name="thisForm">
		<select name="thisSelect" onchange="changeSelectBox()">
			<option value="1">hide 2nd select box</option>
			<option value="2">show 2nd select box</option>
		</select>
		    
		<select name="secondSelect" disabled="true">
			<option value="0">please select an 
option</option>
		</select>
	</form>
</html>