473,699 Members | 2,292 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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] = "accelerato r";
vect[8] = "amanet";
vect[9] = "alegro";
vect[10] = "altu";
vect[11] = "altceva";
<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="makeSu ggestions()">
<input class="box" type="submit" name="submit" id="submit"
<div id="choices">
<b>Suggestion s</b>

[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,ac tion)
if(typeof obj == "string")
obj = document.getEle mentById(obj);
newlnk = document.create Element('a');
newtext = document.create TextNode(txt);
newlnk.setAttri bute('href','#' );
newlnk.setAttri bute('onClick', action);
newlnk.appendCh ild(newtext);
obj.appendChild (newlnk);

// just adds a <br>

function addbr(obj)
if(typeof obj == "string")
obj = document.getEle mentById(obj);
br = document.create Element('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.getEle mentById(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.getEle mentById('nume' ).value = value;
setVisible('cho ices', false);

// function that actually does the search and updates the suggestions

function makeSuggestions ()

if (document.getEl ementById('nume ').value.length == 0) {
setVisible('cho ices',false);
else {
var matches = 0;

clearContainer( 'choices',2);
addbr('choices' );
for (i = 0; i < vect.length; i++) {
if (vect[i].indexOf(docume nt.getElementBy Id('nume').valu e) == 0) {
addbr('choices' );
adda('choices', vect[i],"updateBox( '" + vect[i] + "')");
if (matches == 0) {
setVisible('cho ices',false);
else {
setVisible('cho ices',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 1735
"Radu Ciurlea" <ra*********@gm ail.com> writes:
function adda(obj,txt,ac tion)
{ .... newlnk.setAttri bute('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
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

Logic? IE? Naaaah!

Anyway, just assign a function:

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

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

Good luck.
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.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,ac tion)
if(typeof obj == "string")
obj = document.getEle mentById(obj);
newlnk = document.create Element('a');
newtext = document.create TextNode(txt);
newlnk.setAttri bute('href','Ja vaScript:' + action);
//newlnk.setAttri bute('onClick', action);
newlnk.appendCh ild(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

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 courses to pass the correct option value and then be displayed at the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html I am passing countries, products, and courses. The first two display
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 tags are hanging in ie when generating a html page in a new window. Works fine in netscape/moz. I know ie does some weird things with scripts but...
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 is that after a bit of fiddling I'm getting am 'Object Expected' error when I click on the Depot dropdown which I can't seem to get round. The code I had was working OK but then I cut it all out, tidied it all up, and put it back in and now it...
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" target="_blank" alt="Link to map"> </map>
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 page-design or even worse attacking my site with javascript directives i use stuff like (WebControls.Label)Output.Text = HttpUtility.HtmlEncode(userDefinedData); and my own functions which allow Line-Breaks and handle links. But that way seems not to be...
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 'Button19' of type 'Button' must be placed inside a form tag with runat=server Can the IDE not do what it is supposed to do. It seems that it is a fight to make it do anything or did I do something wrong? It would seem silly to have to create a...
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 HTML. Luckily other interfaces are "modern" using xml file up/downloads without any difficulties... I'm not very used to .NET-environment yet, so I'd appreciate some clues about the classes I should use to implement this stupid interface - stupid...
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 < or several others, it converts them to html, such as &amp; or &lt; which can sometimes cause my scripts not to work. How can I prevent ASP.NET from doing this? Thanks. -- Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
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 on my local machine. In other words... The WEB is really not involved. What I have so far works with a Netscape Browser but what I really need is for it to work in the IE browser or one that I will create
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 files, before the text "<\head>". All the HTML files have this text and I think some kind of search on this string and either replacing "</head>" with the
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.