junestag
11-20-2009, 12:56 AM
I'm trying to enable a disabled text field based on a specific value being selected in a <SELECT> box. Here's the code I'm using:
// JavaScript Document
function showhideYearsInAlaska(obj) {
txt = document.getElementById('residency').options.selectedIndex.value;
if ( txt == 'Alaska' ) {
document.getElementById('years_in_alaska').disabled = false;
}
}
The code for calling this function from the <SELECT> box is as follows:
<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>
However, it's not working...and I don't understand why not.
// JavaScript Document
function showhideYearsInAlaska(obj) {
txt = document.getElementById('residency').options.selectedIndex.value;
if ( txt == 'Alaska' ) {
document.getElementById('years_in_alaska').disabled = false;
}
}
The code for calling this function from the <SELECT> box is as follows:
<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>
However, it's not working...and I don't understand why not.