You could get sort of what I think you want via this tortured path:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function showhideYearsInAlaska(obj) {
var txt = document.getElementById('residency').options[document.getElementById('residency').options.selectedIndex].value;
if ( txt == 'Alaska' ) {
document.getElementById('years_in_alaska').disabled = false;
}
}
</script>
</head>
<body>
<p>
<label for="residency">In what state do you claim official residency?</label>
<select name="residency" id="residency" tabindex="18" onchange="showhideYearsInAlaska(this)">
<option value="select">Select a State</option>
<option value="Alaska" id="Alaska">Alaska</option>
</select>
</p>
<p>
<label for="years_in_alaska">If you claim Alaska residency, how long have you been physically in Alaska?</label>
<input type="text" name="years_in_alaska" id="years_in_alaska" disabled="true" />
</p>
</body>
</html>
Note: Both the obj argument and the this parameter passed to it are unused.
Here is a much simpler method that also allows for the field to become disabled again should the user change their selection:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function showhideYearsInAlaska(val) {
document.getElementById('years_in_alaska').disabled = val !== 'Alaska';
}
</script>
</head>
<body>
<p>
<label for="residency">In what state do you claim official residency?</label>
<select name="residency" id="residency" tabindex="18" onchange="showhideYearsInAlaska(this.value)">
<option value="select">Select a State</option>
<option value="Alaska" id="Alaska">Alaska</option>
</select>
</p>
<p>
<label for="years_in_alaska">If you claim Alaska residency, how long have you been physically in Alaska?</label>
<input type="text" name="years_in_alaska" id="years_in_alaska" disabled="true" />
</p>
</body>
</html>
Now, this just deals with the field becoming enabled or disabled though, which is different from hiding and showing the field. I think you are just going for enabled/disabled. But if you want more, be specific.
Bookmarks