473,789 Members | 2,726 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
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] = "accelerato r";
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="makeSu ggestions()">
<input class="box" type="submit" name="submit" id="submit"
value="Submit">
</form>
</p>
<div id="choices">
<b>Suggestion s</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,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
<div>

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] + "')");
matches++;
}
}
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 1744
"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
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,ac tion)
{
....
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/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

12
6559
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
13
1895
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...
4
2279
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...
68
11204
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>
2
11523
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...
17
2496
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...
2
2292
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...
11
2788
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/
1
3428
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
2
4379
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
0
10412
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10142
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,...
0
9986
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9021
agi2029
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...
1
7529
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5422
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...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3703
muto222
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.