2 Author: Jerome Mouneyrac
3 Bug Reference: http://tracker.moodle.org/browse/MDL-14439
4 IE and Opera fire the onchange when ever you move into a dropdwown list with the keyboard.
5 These functions fix this problem.
12 if I didn't use global variables, we would need to pass them as parameter:
14 I would write "theSelect.onchange = selectChanged(...);"
15 This code causes a javascript error on IE. (not firefox)
16 so I had to write theSelect.onchange = selectChanged; It's why I use global variables .
17 Because I use global variables, I didn't put this code in javascript-static.js.
18 This file is loaded in javascript.php.
21 var select_targetwindow;
23 //we redefine all user actions on the dropdown list
24 //onfocus, onchange, onkeydown, and onclick
25 function initSelect(formId,targetWindow)
27 //initialise global variables
29 select_targetwindow=targetWindow;
31 var theSelect = document.getElementById(select_formid+"_jump");
33 theSelect.changed = false;
37 theSelect.onchange = selectChanged;
38 theSelect.onkeydown = selectKeyed;
39 theSelect.onclick = selectClicked;
44 function selectChanged(theElement)
48 if (theElement && theElement.value)
50 theSelect = theElement;
57 if (!theSelect.changed)
62 //here is the onchange redirection
63 select_targetwindow.location=document.getElementById(select_formid).jump.options[document.getElementById(select_formid).jump.selectedIndex].value;
68 function selectClicked()
73 function selectFocussed()
75 this.initValue = this.value;
80 //we keep Firefox behaviors: onchange is fired when we press "Enter", "Esc", or "Tab"" keys.
81 //note that is probably not working on Mac (keyCode could be different)
82 function selectKeyed(e)
86 var keyCodeEnter = "13";
87 var keyCodeEsc = "27";
98 if ((theEvent.keyCode == keyCodeEnter || theEvent.keyCode == keyCodeTab) && this.value != this.initValue)
103 else if (theEvent.keyCode == keyCodeEsc)
105 this.value = this.initValue;
109 this.changed = false;