Bonjour,

J'ai utilisé le code javascript ci-dessous pour élargir un combobox suivant son contenu et ça marche bien. L'éxecution de ce code se fait par l'évènement onfocus de la balise html select.Mais l'évènement onchange dans la meme balise ,qui lui meme exécute un autre code dans ma page web,devient non fonctionnel, comme si le contexte change lorsque le code javascript s'éxécute.
Quand je le remplace par un autre bout de code , les deux évènements fonctionnent ensemble.

Est ce qu'il ya qqn qui peut m'aider.

merci


Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
<select class="texteListeDeroulante" style="width:85px" name="box" onchange="drop(this.selectedIndex)" onfocus="window.dropdown_menu_hack(this)"> 
<option >a</option> 
<option>b</option> 
<option >c</option> 
<option> d</option> 
</select>

le code de onchange il active ou désactive un textbox (c à d : drop(this.selectedIndex)" )


le code javascript (c àd : dropdown_menu_hack(this)) est le suivant:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
function foo(px,py,pw,ph,baseElement,fid)
{
var win = document.getElementById(this.fid);
}
 
 
function dropdown_menu_hack(el)
{
if(el.runtimeStyle.behavior.toLowerCase()=="none"){return;}
el.runtimeStyle.behavior="none";
 
var ie5 = (document.namespaces==null);
el.ondblclick = function(e)
{
window.event.returnValue=false;
return false;
}
 
if(window.createPopup==null)
{
 
var fid = "dropdown_menu_hack_" + Date.parse(new Date());
 
window.createPopup = function()
{
if(window.createPopup.frameWindow==null)
{
el.insertAdjacentHTML("AfterEnd","<iframe id='"+fid+"' name='"+fid+"' src='about:blank' frameborder='1' scrolling='no'></></iframe>");
var f = document.frames[fid];
f.document.open();
f.document.write("<html><body></body></html>");
f.document.close();
f.fid = fid; 
 
 
var fwin = document.getElementById(fid);
fwin.style.cssText="position:absolute;top:0;left:0;display:none;z-index:99999;";
 
 
f.show = function(px,py,pw,ph,baseElement)
{ 
py = py + baseElement.getBoundingClientRect().top + Math.max( document.body.scrollTop, document.documentElement.scrollTop) ;
px = px + baseElement.getBoundingClientRect().left + Math.max( document.body.scrollLeft, document.documentElement.scrollLeft) ;
fwin.style.width = pw + "px";
fwin.style.height = ph + "px"; 
fwin.style.posLeft =px ;
fwin.style.posTop = py ; 
fwin.style.display="block"; 
}
 
 
f_hide = function(e)
{ 
if(window.event && window.event.srcElement && window.event.srcElement.tagName && window.event.srcElement.tagName.toLowerCase()=="select"){return true;}
fwin.style.display="none";
} 
f.hide = f_hide;
document.attachEvent("onclick",f_hide); 
document.attachEvent("onkeydown",f_hide); 
 
}
return f;
}
}
 
function showMenu()
{
 
function selectMenu(obj)
{ 
var o = document.createElement("option");
o.value = obj.value;
o.innerHTML = obj.innerHTML; 
while(el.options.length>0){el.options[0].removeNode(true);}
el.appendChild(o);
el.title = o.innerHTML; 
el.contentIndex = obj.selectedIndex ;
el.menu.hide(); 
} 
 
 
el.menu.show(0 , el.offsetHeight , 10, 10, el); 
var mb = el.menu.document.body;
 
mb.style.cssText ="border:solid 1px black;margin:0;padding:0;overflow-y:auto;overflow-x:auto;background:white;text-aligbn:center;font-family:Verdana;font-size:12px;";
var t = el.contentHTML;
t = t.replace(/<select/gi,'<ul');
t = t.replace(/<option/gi,'<li');
t = t.replace(/<\/option/gi,'</li');
t = t.replace(/<\/select/gi,'</ul');
mb.innerHTML = t; 
 
 
el.select = mb.all.tags("ul")[0];
el.select.style.cssText="list-style:none;margin:0;padding:0;";
mb.options = el.select.getElementsByTagName("li");
 
for(var i=0;i<mb.options.length;i++)
{
mb.options[i].selectedIndex = i;
mb.options[i].style.cssText = "list-style:none;margin:0;padding:1px 2px;width/**/:100%;cursor:hand;cursor:pointer;white-space:nowrap;"
mb.options[i].title =mb.options[i].innerHTML;
mb.options[i].onmouseover = function()
{
if( mb.options.selected ){mb.options.selected.style.background="white";mb.options.selected.style.color="black";}
mb.options.selected = this;
this.style.background="#333366";this.style.color="white";
}
 
mb.options[i].onmouseout = function(){this.style.background="white";this.style.color="black";}
mb.options[i].onmousedown = function(){selectMenu(this); }
mb.options[i].onkeydown = function(){selectMenu(this); }
 
 
if(i == el.contentIndex)
{
mb.options[i].style.background="#333366";
mb.options[i].style.color="white"; 
mb.options.selected = mb.options[i];
}
}
 
 
var mw = Math.max( ( el.select.offsetWidth + 22 ), el.offsetWidth + 22 );
mw = Math.max( mw, ( mb.scrollWidth+22) );
var mh = mb.options.length * 15 + 8 ; 
 
var mx = (ie5)?-3:0;
var my = el.offsetHeight -2;
var docH = document.documentElement.offsetHeight ;
var bottomH = docH - el.getBoundingClientRect().bottom ; 
 
mh = Math.min(mh, Math.max(( docH - el.getBoundingClientRect().top - 50),100) );
 
if(( bottomH < mh) )
{
 
mh = Math.max( (bottomH - 12),10);
if( mh <100 ) 
{
my = -100 ;
 
}
mh = Math.max(mh,100); 
}
 
 
self.focus(); 
 
el.menu.show( mx , my , mw, mh , el); 
sync=null;
if(mb.options.selected)
{
mb.scrollTop = mb.options.selected.offsetTop;
}
 
 
 
 
window.onresize = function(){el.menu.hide()}; 
}
 
function switchMenu()
{
if(event.keyCode)
{
if(event.keyCode==40){ el.contentIndex++ ;}
else if(event.keyCode==38){ el.contentIndex--; }
}
else if(event.wheelDelta )
{
if (event.wheelDelta >= 120)
el.contentIndex++ ;
else if (event.wheelDelta <= -120)
el.contentIndex-- ;
}else{return true;}
 
 
 
 
if( el.contentIndex > (el.contentOptions.length-1) ){ el.contentIndex =0;}
else if (el.contentIndex<0){el.contentIndex = el.contentOptions.length-1 ;}
 
var o = document.createElement("option");
o.value = el.contentOptions[el.contentIndex].value;
o.innerHTML = el.contentOptions[el.contentIndex].text;
while(el.options.length>0){el.options[0].removeNode(true);}
el.appendChild(o);
el.title = o.innerHTML; 
}
 
if(dropdown_menu_hack.menu ==null)
{
dropdown_menu_hack.menu = window.createPopup();
document.attachEvent("onkeydown",dropdown_menu_hack.menu.hide);
}
el.menu = dropdown_menu_hack.menu ;
el.contentOptions = new Array();
el.contentIndex = el.selectedIndex;
el.contentHTML = el.outerHTML;
 
for(var i=0;i<el.options.length;i++)
{ 
el.contentOptions [el.contentOptions.length] = 
{
"value": el.options[i].value,
"text": el.options[i].innerHTML
}
 
if(!el.options[i].selected){el.options[i].removeNode(true);i--;};
}
 
el.onkeydown = switchMenu;
el.onclick = showMenu;
el.onmousewheel= switchMenu;
 
}