473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Spotlight Search Question

Hi Everyone,

I'm currently trying to follow an example I found in a book a while ago to try to create a spotlight (mac-like) search that filters results as one types. The script that I have works perfectly in Firefox, but does not seem to work successfully in Internet Explorer (I'm using version 7).

Here is the Javascript code I am currently using:

Expand|Select|Wrap|Line Numbers
  1. window.onload = initAll;
  2.  
  3. var xhr = false;
  4. var statesArray = new Array();
  5.  
  6. function initAll() {
  7.     document.getElementById("searchField").onkeyup = searchSuggest;
  8.     xhr = null;
  9.  
  10.     // code for Mozilla, etc.
  11.     if (window.XMLHttpRequest) {
  12.         xhr = new XMLHttpRequest();
  13.     }
  14.  
  15.     // code for IE
  16.     else if (window.ActiveXObject) {
  17.         xhr = new ActiveXObject("Microsoft.XMLHTTP");
  18.     }
  19.     if (xhr != null){
  20.         xhr.onreadystatechange=setStatesArray;
  21.         xhr.open("GET","search.xml",true);
  22.         xhr.send(null);
  23.     } else {
  24.         alert("Your browser does not support XMLHTTP.");
  25.     }
  26. }
  27.  
  28. function setStatesArray() {
  29.   if(xhr.readyState == 4) {
  30.     if(xhr.responseXML) {
  31.       var allStates = xhr.responseXML.getElementsByTagName("item");
  32.       for(var i = 0; i < allStates.length; i++){
  33.         statesArray[i] = allStates[i].getElementsByTagName("label")[0].firstChild;
  34.       } // for
  35.     } // if
  36.     else {
  37.       alert("There was a problem with the request " + xhr.status);
  38.     } // else
  39.   } // if
  40. } // setStatesArray
  41.  
  42. function searchSuggest(){
  43.   var str = document.getElementById("searchField").value;
  44.   document.getElementById("searchField").className = "";
  45.   if(str != "") {
  46.     document.getElementById("popups").innerHTML = "";
  47.     for(var i = 0; i < statesArray.length; i++) {
  48.       var thisState = statesArray[i].nodeValue;
  49.       if(thisState.toLowerCase().indexOf(str.toLowerCase()) == 0){
  50.         var tempDiv = document.createElement("div");
  51.     tempDiv.innerHTML = thisState;
  52.     tempDiv.onclick = makeChoice;
  53.     tempDiv.className = "suggestions";
  54.         document.getElementById("popups").appendChild(tempDiv);
  55.       } // if
  56.     } // for
  57.     var foundCt = document.getElementById("popups").childNodes.length;
  58.     if(foundCt == 0) {
  59.         document.getElementById("searchField").className = "error";
  60.     } // if
  61.   } // if
  62.   else {
  63.     document.getElementById("popups").innerHTML = "";
  64.   } // else
  65. } // searchSuggest
  66.  
  67. function makeChoice(evt){
  68.   var thisDiv = (evt) ? evt.target :window.event.srcElement;
  69.   document.getElementById("searchField").value = thisDiv.innerHTML;
  70.   document.getElementById("popups").innerHTML = "";
  71.  
  72.   //Test Redirection
  73.   if (document.getElementById("searchField").value == "Google") {
  74.     window.location = "http://www.google.com/";
  75.   } // if
  76. } //makeChoice
I believe that the current problem I am having stems from one or two things. First, however, let me explain the problem.

As you can probably tell, this script is used to access a XML document containing values. Then, as a user types their search query into a text box, the script will search through the list of XML values and display the ones that match the user's query. If, however, no matches are found, the className is changed to "error" (causing the input field to turn a shade of yellow).

When I enter any value into the search field in Internet Explorer, even if it is one that should come up with a result, the search field instantly turns yellow, indicating that no matches could be found. I believe that this problem stems from the fact that the array "statesArray" has no value as when I open the javascript error console in IE, I get an error saying:

Expand|Select|Wrap|Line Numbers
  1. var thisState = statesArray[i].nodeValue; is null or not an object.
I've tried replacing nodeValue (which I've read to be a known cause of problems in IE) to textContent or firstChild (both of which work perfectly in Firefox), but I'm still having the problem in IE7.

If anyone can see what I'm doing wrong, information would be greatly appreciated.

Thanks,

MrWelfare
Dec 24 '07 #1
4 1881
iam_clint
1,208 Expert 1GB
Everything looks fine to me, maybe give a link to the broken page.
Dec 27 '07 #2
Alright. Well after inserting multiple alert statements into the code, I've discovered that the issue stems from this line of code (in IE7)

Expand|Select|Wrap|Line Numbers
  1.         xhr.open("GET","search.xml",true);
The only reason I can think I would be getting an "Access Denied" error in the Javascript error console in IE7 is if IE could not, for some reason, access the XML file saved on the hard drive. There are no restrictions placed on the file, so perhaps this issue is arising from the browser security end of things?

If so, does anyone know which settings to turn off/down to fix this? Or if this is not the problem, does anyone know what else it could be?
Jan 1 '08 #3
And now, after playing around with it some more, it seems that the function setStatesArray is not even executing in IE. I placed alerts all throughout the code and tested the results. So far, it seems that Internet Explorer will execute the javascript code until line 20. (Well, I assume this is true since the alert I placed between lines 20 and 21 was displayed). However, the comments that I placed inside the function setStatesArray do not show up at all in IE.

Any help would be greatly appreciated.

Thanks (and Happy New Years! =D)
Jan 1 '08 #4
acoder
16,027 Expert Mod 8TB
See this link for parsing an XML document in IE.
Jan 2 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jim | last post by:
Hi, I have started using Spotlight to monitor a few oracle 8i databases and wonder whether there are any papers detailing what all the indicators are telling me..... Can anyone help? Thanks
0
by: MarionEll | last post by:
Leading Netherlands Firms, Industry Experts in Spotlight at XML Europe 2004 Alexandria, Va. - April 13, 2004 - XML Europe 2004, the premier European forum for the XML community, will feature...
2
by: Rafael Nenninger | last post by:
This question has to do with MS file search but it is happening only with ..asp pages, so I though someone programming with .asp pages has experienced the same situation. I'm trying to find .asp...
19
by: RAJASEKHAR KONDABALA | last post by:
Hi, Does anybody know what the fastest way is to "search for a value in a singly-linked list from its tail" as oposed to its head? I am talking about a non-circular singly-linked list, i.e.,...
28
by: joshc | last post by:
If I have an array of data that I know to be sorted in increasing order, and the array is less than 50 elements, and I want to find the first element greater than a certain value, is a simple...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
0
by: orcl dba | last post by:
I have three Oracle versions installed on my Windows system - Oracle 9.2 database, Oracle 10g client and Oracle 10g database. When I try to create a new database connection in Spotlight, it only...
0
by: =?Utf-8?B?Q29kZVJhem9y?= | last post by:
This is driving me nuts. I really need to watch a video on MSDN spotlight (http://www.microsoft.com/emea/msdn/spotlight/) but every video just stops working every 5 seconds. I've browsed online...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.