annapolistech
asked on
AJAX autocomplete NOT working in IE7
Hi Experts,
I have a code for autocomplete in a html textfield when a user type a text in the textfield the possible text(names) will appear below this field, it is working perfectly in IE6, but not in IE7.
Thanks in advance
Regards,
Sanjay
I have a code for autocomplete in a html textfield when a user type a text in the textfield the possible text(names) will appear below this field, it is working perfectly in IE6, but not in IE7.
Thanks in advance
Regards,
Sanjay
Did you mean to close this or did you still need help with this question? If you still have a question then let me know and I will be happy to help. I will need more info to help you though. If you did mean to close this then explain the C grade. It isn't appropriate (see https://www.experts-exchange.com/help.jsp#hi73 for more info on grading).
bol
bol
ASKER
We need some more solution. we are not able to solve the problem with the solution which you have given us.
Thanks
Thanks
I can't provide a solution without information. Please provide code. Also let me know if you get any javascript errors in IE7. The "solution" I did mention was just a general suggestion but definitely not a solution.
bol
bol
ASKER
We figured out the way to make it work in IE7. There was no problem with the code.
We went to Tools->Internet options->Advanced->Securit y and unchecked "Enable native XMLHTTP support". Since we can't ask user to do this every time, how do we do it programmatically.
Thanks
We went to Tools->Internet options->Advanced->Securit
Thanks
You won't be able to check that box using Javascript or any other client-side script. However if you will provide the code (3rd request), especially the part with the AJAX script, then I might be able to provide a solution so the box won't need to be checked.
bol
bol
ASKER
Hi Bol,
I am posting the AJAX script, hope this will help you detect my problem.
<script type="text/javascript">
var isIE;
var completeTable;
var completeField;
var autorow;
var req;
function getElementY(element){
var targetTop = 0;
if (element.offsetParent) {
while (element.offsetParent) {
targetTop += element.offsetTop;
element = element.offsetParent;
}
} else if (element.y) {
targetTop += element.y;
}
return targetTop;
}
function init() {
completeField = document.getElementById("c omplete-fi eld");
var menu = document.getElementById("a uto-row");
autorow = document.getElementById("m enu-popup" );
autorow.style.top = getElementY(menu) + "px";
completeTable = document.getElementById("c ompleteTab le");
completeTable.setAttribute ("borderco lor", "white");
}
function initRequest(url) {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if (window.ActiveXObject) {
isIE = true;
return new ActiveXObject("Microsoft.X MLHTTP");
}
}
function doCompletion() {
if (completeField.value == "") {
clearTable();
} else {
var url = "autocomplete?action=compl ete&id=" + escape(completeField.value );
var req = initRequest(url);
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {
parseMessages(req.response XML);
} else if (req.status == 204){
clearTable();
}
}
};
req.open("GET", url, true);
req.send(null);
}
}
function parseMessages(responseXML) {
clearTable();
var employees = responseXML.getElementsByT agName("em ployees")[ 0];
if (employees.childNodes.leng th > 0) {
//completeTable.setAttribu te("border color", "black");
//completeTable.setAttribu te("border ", "1");
} else {
clearTable();
}
for (loop = 0; loop < employees.childNodes.lengt h; loop++) {
var employee = employees.childNodes[loop] ;
var firstName = employee.getElementsByTagN ame("first Name")[0];
//var lastName = employee.getElementsByTagN ame("lastN ame")[0];
var employeeId = employee.getElementsByTagN ame("id")[ 0];
appendEmployee(firstName.c hildNodes[ 0].nodeVal ue, employeeId.childNodes[0].n odeValue);
}
}
function clearTable() {
if (completeTable) {
completeTable.setAttribute ("borderco lor", "white");
completeTable.setAttribute ("border", "0");
completeTable.style.visibl e = false;
for (loop = completeTable.childNodes.l ength -1; loop >= 0 ; loop--) {
completeTable.removeChild( completeTa ble.childN odes[loop] );
}
}
}
function appendEmployee(firstName,e mployeeId) {
var firstNameCell;
var lastNameCell;
var row;
var nameCell;
if (isIE) {
row = completeTable.insertRow(co mpleteTabl e.rows.len gth);
nameCell = row.insertCell(0);
} else {
row = document.createElement("tr ");
nameCell = document.createElement("td ");
row.appendChild(nameCell);
completeTable.appendChild( row);
}
row.className = "popupRow";
nameCell.setAttribute("bgc olor", "#FFFAFA");
var linkElement = document.createElement("a" );
linkElement.className = "popupItem";
linkElement.setAttribute(" href", "autocomplete?action=looku p&id=" + employeeId);
linkElement.appendChild(do cument.cre ateTextNod e(firstNam e));
nameCell.appendChild(linkE lement);
}
</script>
Thanks,
Sanjay
I am posting the AJAX script, hope this will help you detect my problem.
<script type="text/javascript">
var isIE;
var completeTable;
var completeField;
var autorow;
var req;
function getElementY(element){
var targetTop = 0;
if (element.offsetParent) {
while (element.offsetParent) {
targetTop += element.offsetTop;
element = element.offsetParent;
}
} else if (element.y) {
targetTop += element.y;
}
return targetTop;
}
function init() {
completeField = document.getElementById("c
var menu = document.getElementById("a
autorow = document.getElementById("m
autorow.style.top = getElementY(menu) + "px";
completeTable = document.getElementById("c
completeTable.setAttribute
}
function initRequest(url) {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if (window.ActiveXObject) {
isIE = true;
return new ActiveXObject("Microsoft.X
}
}
function doCompletion() {
if (completeField.value == "") {
clearTable();
} else {
var url = "autocomplete?action=compl
var req = initRequest(url);
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {
parseMessages(req.response
} else if (req.status == 204){
clearTable();
}
}
};
req.open("GET", url, true);
req.send(null);
}
}
function parseMessages(responseXML)
clearTable();
var employees = responseXML.getElementsByT
if (employees.childNodes.leng
//completeTable.setAttribu
//completeTable.setAttribu
} else {
clearTable();
}
for (loop = 0; loop < employees.childNodes.lengt
var employee = employees.childNodes[loop]
var firstName = employee.getElementsByTagN
//var lastName = employee.getElementsByTagN
var employeeId = employee.getElementsByTagN
appendEmployee(firstName.c
}
}
function clearTable() {
if (completeTable) {
completeTable.setAttribute
completeTable.setAttribute
completeTable.style.visibl
for (loop = completeTable.childNodes.l
completeTable.removeChild(
}
}
}
function appendEmployee(firstName,e
var firstNameCell;
var lastNameCell;
var row;
var nameCell;
if (isIE) {
row = completeTable.insertRow(co
nameCell = row.insertCell(0);
} else {
row = document.createElement("tr
nameCell = document.createElement("td
row.appendChild(nameCell);
completeTable.appendChild(
}
row.className = "popupRow";
nameCell.setAttribute("bgc
var linkElement = document.createElement("a"
linkElement.className = "popupItem";
linkElement.setAttribute("
linkElement.appendChild(do
nameCell.appendChild(linkE
}
</script>
Thanks,
Sanjay
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi Bol,
Also having the same problems getting this to example to work in IE7...it works fine in Firefox, IE6 but not IE7. I added the alerts that you suggested and I get back 'undefined' for isIE which is expected. For the next alert I get back [object] and that is it. Any ideas?
Also having the same problems getting this to example to work in IE7...it works fine in Firefox, IE6 but not IE7. I added the alerts that you suggested and I get back 'undefined' for isIE which is expected. For the next alert I get back [object] and that is it. Any ideas?
@Nickn777 - Feel free to continue to monitor this but if you want direct help then, as Vee_Mod said, you really should open a new question. I don't mind if you post the URL of that question here to draw my attention to it if you wish. I was holding off on testing IE7 myself to see what Annapolistech's response would be but I will take some time to look at it now.
Annapolistech,
If you do use my suggestion and get the same result then try using the line below for the second alert.
alert(req.xml);
Let me know the results of that too. It has been a while since I have looked at this and I will wait for your reply before spending more time on the specifics here.
bol
Annapolistech,
If you do use my suggestion and get the same result then try using the line below for the second alert.
alert(req.xml);
Let me know the results of that too. It has been a while since I have looked at this and I will wait for your reply before spending more time on the specifics here.
bol
I tested one of my more common AJAX pages that deals with xml and it works fine in IE7 with or without "Enable native XMLHTTP support" checked. That means a problem is related to the script and not a general lack of support in IE7 for AJAX. This confirms what I thought but I wanted to test and post the result after Nickn777's comment.
bol
bol
annapolistech,
Any particular reason your participation here is limited to assigning a B grade? Even after the first offense I tried to help in good faith that you would appreciate and recognize it. I guess I shouldn't be surprised when I see your question history but you won't get good help if you aren't a good and considerate member.
@Vee_Mod - Please correct the grade or take whatever administrative action you feel appropriate. Thanks!
bol
Any particular reason your participation here is limited to assigning a B grade? Even after the first offense I tried to help in good faith that you would appreciate and recognize it. I guess I shouldn't be surprised when I see your question history but you won't get good help if you aren't a good and considerate member.
@Vee_Mod - Please correct the grade or take whatever administrative action you feel appropriate. Thanks!
bol
V,
Thanks!
bol
Thanks!
bol
bol