D
dan
Hi
I'm creating a very basic Ajax "Suggest" type script. I have the
server side OK, and the response gets back OK. I've had to use
responseText, as for some reason xmlResponse doesn't seem to work if
more than one <message> element is present. But that isn't the point
of this post, so I'd better get to that.
Once I have the list of values that match the user's search term, I
display them as a list in a <div>. When the user clicks on one of the
list, that value is placed into the textfield.
Here are three ways I attempted this, but the only one that allows
anything other than the last element to accept any kind of focus is
the one that uses innerHTML for the entire thing.
Can anyone tell me why the other two don't work? They all display
pretty much the same, until you move the cursor over the list. The
last two automatically move the focus to the last item on the list. I
should add that I've only tested these in IE 6, and Firefox 2 (both
for Windows).
Any pointers with this very much appreciated.
Cheers
Dan
Assume all of the following are performed within a for loop
// This is the one that works
ss.innerHTML += "<div class='norm' onmouseover=
\"javascript:this.className='over'\" onmouseout=
\"javascript:this.className='norm'\" " +
"onclick='SetSearch(this.innerHTML)'>" + text + "</div>";
// This doesn't work
var d = document.createElement('div');
ss.appendChild(d);
d.innerHTML = text;
d.className = 'norm';
d.onmouseover = function() { d.className = 'over'; };
d.onmouseout = function() { d.className = 'norm'; };
d.onclick = function() { SetSearch(text); };
// This doesn't work
var li = document.createElement('li');
li.style.marginBottom = '3px';
var a = document.createElement('a');
var content = document.createTextNode(text);
a.appendChild(content);
a.setAttribute('title', text);
a.setAttribute('href', text);
li.appendChild(a);
u.appendChild(li);
a.onclick=function() { SetSearch(a.getAttribute('href')); return
false;};
I'm creating a very basic Ajax "Suggest" type script. I have the
server side OK, and the response gets back OK. I've had to use
responseText, as for some reason xmlResponse doesn't seem to work if
more than one <message> element is present. But that isn't the point
of this post, so I'd better get to that.
Once I have the list of values that match the user's search term, I
display them as a list in a <div>. When the user clicks on one of the
list, that value is placed into the textfield.
Here are three ways I attempted this, but the only one that allows
anything other than the last element to accept any kind of focus is
the one that uses innerHTML for the entire thing.
Can anyone tell me why the other two don't work? They all display
pretty much the same, until you move the cursor over the list. The
last two automatically move the focus to the last item on the list. I
should add that I've only tested these in IE 6, and Firefox 2 (both
for Windows).
Any pointers with this very much appreciated.
Cheers
Dan
Assume all of the following are performed within a for loop
// This is the one that works
ss.innerHTML += "<div class='norm' onmouseover=
\"javascript:this.className='over'\" onmouseout=
\"javascript:this.className='norm'\" " +
"onclick='SetSearch(this.innerHTML)'>" + text + "</div>";
// This doesn't work
var d = document.createElement('div');
ss.appendChild(d);
d.innerHTML = text;
d.className = 'norm';
d.onmouseover = function() { d.className = 'over'; };
d.onmouseout = function() { d.className = 'norm'; };
d.onclick = function() { SetSearch(text); };
// This doesn't work
var li = document.createElement('li');
li.style.marginBottom = '3px';
var a = document.createElement('a');
var content = document.createTextNode(text);
a.appendChild(content);
a.setAttribute('title', text);
a.setAttribute('href', text);
li.appendChild(a);
u.appendChild(li);
a.onclick=function() { SetSearch(a.getAttribute('href')); return
false;};