473,395 Members | 1,521 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,395 software developers and data experts.

html/JavaScript/DOM problems under IE

Hello. I want to make the browser show some suggestions under a text
box (like the To: field in webmail interfaces that displays addresses
in the addressbook). Basically whenever something changes in the text
box (i.e. an onKeyUp even occurs) I check to see what words in the
"address book" match the word in the box. After that I fill a <div>
with links that onClick update the text box contents. Here's how it's
written:

in search.html:

[stuff removed]
<script type="text/javascript">
// potential choices go here(nevermind the language :)
var vect = new Array();
vect[0] = "asa";
vect[1] = "acasa";
vect[2] = "ana are mere";
vect[3] = "android";
vect[4] = "analgezic";
vect[5] = "asin";
vect[6] = "as";
vect[7] = "accelerator";
vect[8] = "amanet";
vect[9] = "alegro";
vect[10] = "altu";
vect[11] = "altceva";
</script>
<script type="text/javascript" src="search.js"></script>

[more stuff removed]

<form name="f1" id="f1">
<input class="box" type="text" id="nume" style="width : 200px;"
onkeyup="makeSuggestions()">
<input class="box" type="submit" name="submit" id="submit"
value="Submit">
</form>
</p>
<div id="choices">
<b>Suggestions</b>
</div>

[the rest is irrelevant]

and in search.js:

// this function adds the links. i tell it where to add them, what text
they should have and what onClick action

function adda(obj,txt,action)
{
if(typeof obj == "string")
obj = document.getElementById(obj);
newlnk = document.createElement('a');
newtext = document.createTextNode(txt);
newlnk.setAttribute('href','#');
newlnk.setAttribute('onClick',action);
newlnk.appendChild(newtext);
obj.appendChild(newlnk);
}

// just adds a <br>

function addbr(obj)
{
if(typeof obj == "string")
obj = document.getElementById(obj);
br = document.createElement('br');
obj.appendChild(br);
}

// deletes all child nodes of obj, except for the first [keepnodes]

function clearContainer(obj,keepnodes)
{
if(typeof obj == "string")
obj = document.getElementById(obj);
while (obj.childNodes.length != keepnodes) {
obj.removeChild(obj.lastChild);
}
}

// this updates the text box. alert() there for debugging purposes
function updateBox(value)
{
alert('in updateBox()');
document.getElementById('nume').value = value;
setVisible('choices', false);
}

// function that actually does the search and updates the suggestions
<div>

function makeSuggestions()
{

if (document.getElementById('nume').value.length == 0) {
setVisible('choices',false);
}
else {
var matches = 0;

clearContainer('choices',2);
addbr('choices');
for (i = 0; i < vect.length; i++) {
if (vect[i].indexOf(document.getElementById('nume').value) == 0) {
addbr('choices');
adda('choices',vect[i],"updateBox('" + vect[i] + "')");
matches++;
}
}
if (matches == 0) {
setVisible('choices',false);
}
else {
setVisible('choices',true);
}
}
}

choices starts as a hidden layer. When the user changes something the
script checks to see wether there are matches in vect[] for the text in
'nume'. If there aren't any the choices <div> is hidden. If there are
available choices they are displayed in the choices <div>. When the
user clicks one of the choices' links the value in 'nume' is updated
and the choices <div> is hidden.

This all works fine in Firefox and Opera. IE however doesn't update the
text box when the links are clicked. I inserted an alert() in the code
in the updateBox() function, to see if it gets called, and it doesn't.
So I believe IE doesn't properly assign the onClick attribute to the
link. Unfortunately there is no DOM inspector (like in FF), so all I
can do is guess what's wrong. IE won't display any errors.

Any ideas? What's wrong with the code? setAttribute() is a standard
method (W3 says) so it should work. It sets the 'href' part right, so I
can't see why 'onClick' won't work.

Jul 23 '05 #1
2 1702
"Radu Ciurlea" <ra*********@gmail.com> writes:
function adda(obj,txt,action)
{ .... newlnk.setAttribute('onClick',action); .... } ..... adda('choices',vect[i],"updateBox('" + vect[i] + "')"); I inserted an alert() in the code in the updateBox() function, to
see if it gets called, and it doesn't. So I believe IE doesn't
properly assign the onClick attribute to the link. Unfortunately
there is no DOM inspector (like in FF), so all I can do is guess
what's wrong. IE won't display any errors.
You are correct. IE doesn't parse updates to DOM attributes for event
handlers.
Any ideas? What's wrong with the code? setAttribute() is a standard
method (W3 says) so it should work.
You surely set the attribute. It just doesn't update the live part of
the DOM element, only what it considers the source code that lead to it.
It sets the 'href' part right, so I can't see why 'onClick' won't
work.


Logic? IE? Naaaah!

Anyway, just assign a function:

----
function adda(obj,txt,action)
{
....
obj.onclick = action;
....
}
....
function makeUpdateCall(value) {
return function(){
updateBox(value);
};
}

function makeSuggestions()
{
....
adda('choices', vect[i], makeUpdateCall(vect[i]));
....
---

Good luck.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #2
It was pretty dumb of me not to think of this in the first place, but
here goes:

function adda(obj,txt,action)
{
if(typeof obj == "string")
obj = document.getElementById(obj);
newlnk = document.createElement('a');
newtext = document.createTextNode(txt);
newlnk.setAttribute('href','javascript:' + action);
//newlnk.setAttribute('onClick',action);
newlnk.appendChild(newtext);
obj.appendChild(newlnk);
}

Quick and dirty.

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
13
by: nobody | last post by:
Hello all, I've searched just about everything and although I can see that other people are having problems, but theirs don't seem to relate, so in a last ditch attempt, my posting! Script...
4
by: cjm | last post by:
I have two problems that I suspect will be bread-and-butter problems for the more experienced guys on here, but I'm not the greatest with js. NB: Code snippets at the bottom The first problem...
68
by: Steve | last post by:
Hi There, Prob a simple answer to this (I hope) but I can't quite work it out yet... I have this in a page: <map name="Map"> <area shape="rect" coords="43,68,52,77" href="map.html"...
2
by: ViperDK | last post by:
What is the best way for that? I store all Data in the original form in the Database. To prevent output fields (especially the fields everyone can use) to do bad things like killing the...
17
by: Lloyd Sheen | last post by:
This IDE is driving me nuts. I needed another button so I copied an existing one, changed the Text and the id and position by drag and drop. Well then I run and get the following: Control...
2
by: Esa | last post by:
Hi, I'm having problems with one strange web system where submitting an application and making queries about its handling status require a series of form submits and response parsing - all in...
11
by: Nathan Sokalski | last post by:
I add several JavaScript events (onchange, onkeypress, etc.) to Controls using the Add method of the Attributes collection. However, if the JavaScript code contains certain characters, such as & or...
1
by: kevin.a.sweeney | last post by:
I would like to open an application from a hyperlink on a webpage. 1. the webpage is located on my local machine. 2. the application is located on my local machine. 3. the application will run...
2
by: Slain | last post by:
I have a big list of HTML files, which need to be updated with a common text. <script language=JavaScript src="./highlight.js"></script> I need to add the above line in each of the html...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.