I inherited the site! which was designed to work in IE and only IE. It seems I was asked to run the site in Firefox. I fixed most of the errors without any problems, but I have a dead end.
setTimeout (fDelayedFunc, 1000);
This Javascript line works fine in IE, but in Firefox, the fDelayedFunc function never works. I removed setTimeout and the shell of the function and tried to run the code as part of the main function. This works without any problems.
There is a lot of code, but the main thing here, but I have problems. If you want to see more code, please let me know.
setTimeout(fDelayedFunc, 0);
var vCurrentTBValue = vJQElement.val();
function fDelayedFunc() {
if (vJQElement.val() == vCurrentTBValue) {
alert("test");
var vTop = vJQElement.position().top + 25;
var vLeft = vJQElement.position().left;
if (vHiddenFieldToWriteTo == "#ctl00_ContentPlaceHolder1_hfAccountCode") {
vTop = vJQElement.position().top + 58;
vLeft = vJQElement.position().left + 200;
}
else {
vTop = vJQElement.position().top + 25;
vLeft = vJQElement.position().left;
}
var vDivElement = $("<div id='divSearchBox' style='position:absolute; top:" + vTop + ";left:" + vLeft + "; z-index: 40000;'></div>");
var vListBox = $("<select id='lbResults' tabIndex='" + vJQElement.attr("tabIndex") + "' size='4' style='height:400px;'></select>");
vListBox.bind("keydown", function() {
if (event.keyCode == 9 || event.keyCode == 13) {
$(vHiddenFieldToWriteTo).val($(vListBox.find(":selected")).val());
$('#ctl00_ContentPlaceHolder1_wizNewConsignment_btnRefresh').click();
}
else if (event.keyCode == 38 && $(vListBox.find(":selected")).val() == $(vListBox.find(":first")).val()) {
vElement.focus();
}
}).bind("dblclick", function() {
$(vHiddenFieldToWriteTo).val($(vListBox.find(":selected")).val());
$('#ctl00_ContentPlaceHolder1_wizNewConsignment_btnRefresh').click();
});
var vSearchText = vJQElement.val();
var vDepotID = $("#ctl00_ContentPlaceHolder1_wizNewConsignment_hfDepotID").val();
var vCustomerID = $("#ctl00_ContentPlaceHolder1_wizNewConsignment_hfCustomerID").val();
var vCountryID = $("#ctl00_ContentPlaceHolder1_wizNewConsignment_hfCountryID").val();
var vConsignee = vJQElement.attr("boolConsignee");
vJQElement.css("backgroundImage", "url(images/small-loader.gif)");
vJQElement.css("backgroundRepeat", "no-repeat");
vJQElement.css("backgroundPosition", "right");
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "NewConsignment.asmx/fGetAddressesAndIDs",
data: "{'strSearchText' : '" + vSearchText + "', 'intDepotID' : '" + vDepotID + "', 'intCustomerID' : '" + vCustomerID + "', 'intCountryID' : '" + vCountryID + "', 'boolConsignee' : '" + vConsignee + "'}",
dataType: "json",
success: function fGetAddressesAndIDsResult(GetAddressesAndIDsResult) {
if (GetAddressesAndIDsResult != null && GetAddressesAndIDsResult != "") {
var vNumberOfResults = 0;
var vNumberOfLearntAddresses = 0;
var vLearntAddressUniqueID = "";
try {
if (GetAddressesAndIDsResult.d.length > 0) {
$.each(GetAddressesAndIDsResult.d, function() {
if (this.length > 0) {
var vAddress = eval("(" + this + ")");
var vOption = $("<option class='AddressOption' value='" + vAddress.uniqueID + "'>" + vAddress.briefDescription + "</option>");
if (vAddress.uniqueID.indexOf("ConLA") != -1) {
vNumberOfLearntAddresses++;
vLearntAddressUniqueID = vAddress.uniqueID;
}
vListBox.append(vOption);
vNumberOfResults++;
}
});
}
}
catch (err) {
$.each(GetAddressesAndIDsResult, function() {
if (this.length > 0) {
var vAddress = eval("(" + this + ")");
var vOption = $("<option class='AddressOption' value='" + vAddress.uniqueID + "'>" + vAddress.briefDescription + "</option>");
if (vAddress.uniqueID.indexOf("ConLA") != -1) {
vNumberOfLearntAddresses++;
vLearntAddressUniqueID = vAddress.uniqueID;
}
vListBox.append(vOption);
vNumberOfResults++;
}
});
}
if (vNumberOfLearntAddresses == 1) {
$(vHiddenFieldToWriteTo).val(vLearntAddressUniqueID);
$('#ctl00_ContentPlaceHolder1_wizNewConsignment_btnRefresh').click();
}
vDivElement.append(vListBox);
if (vNumberOfResults != 0) {
$("body").append(vDivElement);
vListBox.find(".AddressOption:first").attr("selected", "true");
}
}
vJQElement.css("backgroundImage", "none");
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("An error occured, please try again");
vJQElement.css("backgroundImage", "none");
}
});
}
}