summaryrefslogtreecommitdiffstats
path: root/skins/common/htmlform.js
blob: 2045ab484572acca6bd004456b8f88aa366359b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Find select-or-other fields.
addOnloadHook( function() {
	var fields = getElementsByClassName( document, 'select', 'mw-htmlform-select-or-other' );

	for( var i = 0; i < fields.length; i++ ) {
		var select = fields[i];

		addHandler( select, 'change', htmlforms.selectOrOtherSelectChanged );

		// Use a fake 'e' to update it.
		htmlforms.selectOrOtherSelectChanged( { 'target': select } );
	}
} );

var htmlforms = {
	'selectOrOtherSelectChanged' : function( e ) {
		var select;
		if ( !e ) {
			e = window.event;
		}
		if ( e.target ) {
			select = e.target;
		} else if ( e.srcElement ) {
			select = e.srcElement;
		}
		if ( select.nodeType == 3 ) { // defeat Safari bug
			select = select.parentNode;
		}

		var id = select.id;
		var textbox = document.getElementById( id + '-other' );

		if ( select.value == 'other' ) {
			textbox.disabled = false;
		} else {
			textbox.disabled = true;
		}
	}
}