/    Sign up×
Community /Pin to ProfileBookmark

Setting functions to Events in Explorer fails.

The code below is part of a tool tip set of functions. Currently this fails in Explorer as soon as it tries to set the event handlers to an instance of the functions. So in this case “initToolTipElements” is only printed once to the alert box and then the script stops. The code works fine in Firefox.

This is the doc type to the HTML page.

[CODE]<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>[/CODE]

Failing function.

[CODE]function initToolTipElements()
{
var ttEls=document.getElementsByName(‘toolTip’);

//Looks like this is only being run once in explorer.
for (i=0;i<=5;i++)
{
alert(“initToolTipElements”);
ttEls[i].onmouseover=addMapToolTip;
ttEls[i].onmousemove=Locate;
ttEls[i].onmouseout=removeToolTip;
}
}
[/CODE]

Can any one tell me where to look for the problem?

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@KorMar 15.2010 — what kind of elements (what tags) are those with the [B]name="toolTip"[/B]?

On the other hand, your javascript code is embedded or external?
Copy linkTweet thisAlerts:
@penauthorMar 15.2010 — Thanks for responding. I have two tests running. One is what I'm aiming at which is an <area> tag

[CODE]<map name="EarthMap_600_imageMap_Map" id="EarthMap_600_imageMap_Map">
<area shape="rect" coords="70,86,95,103" href="#" alt="BritishColumbia" name="toolTip" toolTip="British Columbia"/>
</map>[/CODE]


and the other is this test that is on line.

http://www.penproductions.ca/testToolTip.html

When the mouse is over the blue rectangle it should pop up a simple tool tip.

Thanks for any help that you can provide.
Copy linkTweet thisAlerts:
@KorMar 15.2010 — First: the [B]name[/B] attribute is not to be used upon [I]all[/I] the HTML elements. In fact, for the modern browsers and under the last Doctype versions, there are only several elements which can bear a [B]name[/B] (and which are to be found on using DOM [B]getElementsByName()[/B] method. [I]<AREA> is not one of them[/I].

Have you considered the use of the simple HTML attribute TITLE (no javascript code needed)?

http://www.w3schools.com/tags/att_standard_title.asp
Copy linkTweet thisAlerts:
@penauthorMar 15.2010 — Ah I see, OK so is there a getElementsByTitle function in JS? If now how would I go about collecting all the elements with a known title? Would this require a recursive function and go through all tags in the body and collect them?
Copy linkTweet thisAlerts:
@penauthorMar 16.2010 — Is there no more advise on this?
Copy linkTweet thisAlerts:
@jwstockwellMar 16.2010 — I think he's referring to this

<Div title="this could be your tool tip">Put your mouse here</Div>

Put that on a page and see what it does
Copy linkTweet thisAlerts:
@penauthorMar 16.2010 — Thanks, I didn't know about those tool tips how ever that is not what I'm looking for in the final product. I really do need to use JS to get more data into a nicely formated popup that tracks the mouse.

What I have works, just not in IE, so I gather that I need to find another way to collect the correct tags that will get the popups.

What I have is a parameter in any given tag that is called toolTip="someName" and I use that property value to display the correct information.

At the moment I'm looking at writing a recursive function that will search the page for any tab with a toolTip property. Is that the best way to go about doing that? The tag could be a div, an area, or other.
Copy linkTweet thisAlerts:
@penauthorMar 16.2010 — So can you tell me why this recursive function doesn't continue. It only runs down the first branches and stops and does not continue after that.

[CODE]function initToolTipRecursive(el)
{
for (i=0;i<el.children.length;i++)
{
alert(el.children[i].tagName);
initToolTipRecursive(el.children[i]);
}
}[/CODE]
Copy linkTweet thisAlerts:
@penauthorMar 18.2010 — Thanks for the help, here is what I was shooting for and so far it is working on several browsers correctly. It is the map section of the site that now has nice little pop ups to display the clientele in that area.

http://www.penproductions.ca/

If any one sees any problems in any browser please let me know. I don't care about old browsers as any one coming to our site will be on the latest machines and software as a two year old machine is way out of date for us.
×

Success!

Help @pen spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...