dfwalton
Programmer
- Jul 24, 2002
- 143
My js skills have rusted to the point of uselessness. Have a script that still works fine in IE, but not in FF, and I do not understand why.
Module in ColdFusion is used to assign employees to work crews. Form element is supposed to (and used to) look up name as operator started typing last name.
Relevant JS code:
var isOpera = navigator.userAgent.indexOf('Opera') > -1;
var isIE = navigator.userAgent.indexOf('MSIE') > 1 && !isOpera;
var isMoz = navigator.userAgent.indexOf('Mozilla/5.') == 0 && !isOpera;
var cf2js = new Array(1);
<cfset jsCount=0>
<cfset unList="#empList#">
<cfloop list="#unlist#" index="un" delimiters="~">
cf2js[#jsCount#]='#JSStringFormat(un)#';
<cfset jsCount = jsCount + 1>
</cfloop>
function textboxSelect (oTextbox, iStart, iEnd) {
switch(arguments.length) {
case 1:
oTextbox.select();
break;
case 2:
iEnd = oTextbox.value.length;
/* falls through */
case 3:
if (isIE) {
var oRange = oTextbox.createTextRange();
oRange.moveStart("character", iStart);
oRange.moveEnd("character", -oTextbox.value.length + iEnd);
oRange.select();
} else if (isMoz){
oTextbox.setSelectionRange(iStart, iEnd);
}
}
oTextbox.focus();
}
function autocomplete(oTextbox, oEvent, arrValues, posnum, position, avail, bid, week,month, rate) {
switch (oEvent.keyCode) {
case 38: //up arrow
case 40: //down arrow
case 37: //left arrow
case 39: //right arrow
case 33: //page up
case 34: //page down
case 36: //home
case 35: //end
case 13: //enter
case 9: //tab
case 27: //esc
case 16: //shift
case 17: //ctrl
case 18: //alt
case 20: //caps lock
case 8: //backspace
case 46: //delete
return true;
break;
default:
textboxReplaceSelect(oTextbox, String.fromCharCode(isIE ? oEvent.keyCode : oEvent.charCode));
var iLen = oTextbox.value.length;
var sMatch = autocompleteMatch(oTextbox.value, arrValues);
if (sMatch != null) {
//name = sMatch.substring(0, len1 -1);
//num= sMatch.substring(len1+1);
posnum.disabled= false;
position.disabled=false;
avail.disabled= false;
bid.disabled= false;
week.disabled= false;
month.disabled= false;
rate.disabled= false;
var arr=sMatch.split("^");
name = arr[0];
posnum.value=arr[1];
position.value=arr[2];
avail.value=arr[3];
bid.value=arr[4];
week.value=arr[5];
month.value=arr[6];
rate.value=arr[7];
<!--- posnum.disabled= true;
//position.disabled=true;
//avail.disabled= true;
//bid.disabled= true;
//week.disabled= true;
//month.disabled= true; --->
rate.disabled= false;
oTextbox.value = name;
textboxSelect(oTextbox, iLen, oTextbox.value.length);
}
return false;
}
}
ColdFusion Form snippet:
<td><input type="text" name="emp#qryEPD.posnum#" value = "#qryEpd.EmpName#" id = "txt1" tabindex="#tabInd#"
onFocus="this.select()"
onKeypress="return autocomplete(this, event, cf2js, getElementById('empNum#qryEpd.Posnum#'),
getElementById('empHomePos#qryEpd.Posnum#'),
getElementById('empAvail#qryEpd.Posnum#'),
getElementById('empBid#qryEpd.Posnum#'),
getElementById('empWeek#qryEpd.Posnum#'),
getElementById('empMonth#qryEpd.Posnum#'),
getElementById('Rate#qryEpd.Posnum#'))"
width = "50" size="50")>
<br><font class="body8pt">
Emp. Num: <input type="Text" name="empNum#qryEpd.posnum#" value = "#qryEPD.EmpNum#" id="empNum#qryEpd.Posnum#"
width="5" size="5" class="body8ptbold" tabindex="-1"></font>
<font class="body8pt">
Emp Pos:<input type="text" name="empHomePos#qryEPD.posnum#" value = "" id="empHomePos#qryEPD.posnum#" width="4" size="4" class="body8ptbold" tabindex="-1">
Any hints would be greatly appreciated.
Thanks
David
Module in ColdFusion is used to assign employees to work crews. Form element is supposed to (and used to) look up name as operator started typing last name.
Relevant JS code:
var isOpera = navigator.userAgent.indexOf('Opera') > -1;
var isIE = navigator.userAgent.indexOf('MSIE') > 1 && !isOpera;
var isMoz = navigator.userAgent.indexOf('Mozilla/5.') == 0 && !isOpera;
var cf2js = new Array(1);
<cfset jsCount=0>
<cfset unList="#empList#">
<cfloop list="#unlist#" index="un" delimiters="~">
cf2js[#jsCount#]='#JSStringFormat(un)#';
<cfset jsCount = jsCount + 1>
</cfloop>
function textboxSelect (oTextbox, iStart, iEnd) {
switch(arguments.length) {
case 1:
oTextbox.select();
break;
case 2:
iEnd = oTextbox.value.length;
/* falls through */
case 3:
if (isIE) {
var oRange = oTextbox.createTextRange();
oRange.moveStart("character", iStart);
oRange.moveEnd("character", -oTextbox.value.length + iEnd);
oRange.select();
} else if (isMoz){
oTextbox.setSelectionRange(iStart, iEnd);
}
}
oTextbox.focus();
}
function autocomplete(oTextbox, oEvent, arrValues, posnum, position, avail, bid, week,month, rate) {
switch (oEvent.keyCode) {
case 38: //up arrow
case 40: //down arrow
case 37: //left arrow
case 39: //right arrow
case 33: //page up
case 34: //page down
case 36: //home
case 35: //end
case 13: //enter
case 9: //tab
case 27: //esc
case 16: //shift
case 17: //ctrl
case 18: //alt
case 20: //caps lock
case 8: //backspace
case 46: //delete
return true;
break;
default:
textboxReplaceSelect(oTextbox, String.fromCharCode(isIE ? oEvent.keyCode : oEvent.charCode));
var iLen = oTextbox.value.length;
var sMatch = autocompleteMatch(oTextbox.value, arrValues);
if (sMatch != null) {
//name = sMatch.substring(0, len1 -1);
//num= sMatch.substring(len1+1);
posnum.disabled= false;
position.disabled=false;
avail.disabled= false;
bid.disabled= false;
week.disabled= false;
month.disabled= false;
rate.disabled= false;
var arr=sMatch.split("^");
name = arr[0];
posnum.value=arr[1];
position.value=arr[2];
avail.value=arr[3];
bid.value=arr[4];
week.value=arr[5];
month.value=arr[6];
rate.value=arr[7];
<!--- posnum.disabled= true;
//position.disabled=true;
//avail.disabled= true;
//bid.disabled= true;
//week.disabled= true;
//month.disabled= true; --->
rate.disabled= false;
oTextbox.value = name;
textboxSelect(oTextbox, iLen, oTextbox.value.length);
}
return false;
}
}
ColdFusion Form snippet:
<td><input type="text" name="emp#qryEPD.posnum#" value = "#qryEpd.EmpName#" id = "txt1" tabindex="#tabInd#"
onFocus="this.select()"
onKeypress="return autocomplete(this, event, cf2js, getElementById('empNum#qryEpd.Posnum#'),
getElementById('empHomePos#qryEpd.Posnum#'),
getElementById('empAvail#qryEpd.Posnum#'),
getElementById('empBid#qryEpd.Posnum#'),
getElementById('empWeek#qryEpd.Posnum#'),
getElementById('empMonth#qryEpd.Posnum#'),
getElementById('Rate#qryEpd.Posnum#'))"
width = "50" size="50")>
<br><font class="body8pt">
Emp. Num: <input type="Text" name="empNum#qryEpd.posnum#" value = "#qryEPD.EmpNum#" id="empNum#qryEpd.Posnum#"
width="5" size="5" class="body8ptbold" tabindex="-1"></font>
<font class="body8pt">
Emp Pos:<input type="text" name="empHomePos#qryEPD.posnum#" value = "" id="empHomePos#qryEPD.posnum#" width="4" size="4" class="body8ptbold" tabindex="-1">
Any hints would be greatly appreciated.
Thanks
David