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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enable / Disable Text Field 1

Status
Not open for further replies.

Rieekan

Programmer
Apr 2, 2001
737
US
I'm trying to enable / disable a text field based on a user selecting a specific option in a multiple select list. The value of the item that I want to base the enabling / disabling from is value 11.

I have the code below, but it doesn't seem to work when more than one item is chosen.

Code:
function OtherEnablement() {
	var list = document.forms[0].key_initiative;
	if ( ! list.options ) return;
	var value = list.options[list.selectedIndex].value;
	var otherDisabled = (value != '11');
	var field = document.getElementById('initiative_other');
	field.disabled = otherDisabled;
	if (field.disabled) field.value = '';
	var label = document.getElementById('initiative_other');
	label.disabled = otherDisabled;
}

Any help is appreciated.

- Rieekan
 
something like:

Code:
function OtherEnablement() {
    var list = document.forms[0].elements['key_initiative'].options;
    for (var i = 0; i < list.length; i++) {
        if (list[i].selected && list[i].value == '11') {
            document.forms[0].elements['initiative_other'].disabled = true;
            break;
        }
    }
}

*cLFlaVA
----------------------------
[tt]a frickin' twelve-gauge, what do you think?[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top