# JavaScript: to add onMouseOver (clientside)



## Mr Red (Dec 1, 2008)

Hi

I have been doing this for years on http://www.users.waitrose.com/~cresby/ses/sesc.htm

The call is added using JavaScript to speed loading (the dial-ups are still out there)

Recently I tried changing the function call to include a parameter and it failed. Am I trying the impossible?

I could code it in HTML (which seems to perversely work) and it would not be tiresome because my HTML is coded with VBA (as if by hand to reduce bulk and increase speed) but it does add bulk. There are a lot of links carrying Post Codes. The data are tabular and numerous.

However I try to keep the bulk down. The example page is a successful attempt to split the data in logical sections like day or location.

So can I code JavaScript to add calls with parameters or must I code in HTML?

Ideas welcome. TIA


----------



## Mr Red (Dec 1, 2008)

Perhaps I should add that the intention is to keep it compatible with as many browsers as possible so some JavaScript cannot be used.
I test on IE5.5, Mozilla 1.summit Opera 5 and FF2.

onMouseOver seems the only simple way to do it. I haven't yet found how to transfer the contents of the link (or Alt or Title) during an onMouseOver event if added in JavaScript. In HTML at compile time has worked.


----------



## -Fabez- (Jul 28, 2008)

So what exactly do you want your JavaScript code to do ?


----------



## Mr Red (Dec 1, 2008)

I was trying to replicate the Alt/Title pop-up but make it a tad more obvious.
I have code to keep the layer in one place regardless of scrolling.

The Alt/Title text is derived from the Hyperlink and gives location info that can be used on satnavs. Some surfers ask if I could add it. Obviously they don't look too closely and the Alt/Title pop-up times-out anyway.

Once it is obvious they will stop asking. The problem is to get the text transferred to the calling statement. This works in HTML but I was trying to keep the HTML short so that it loads quickly over dial-up (the lowest common denominator IMO)

Clientside makes it simple and cheap for me. IE5.5, Opera 5, FF 2 and Moczilla 1.0XXXX are used to verify it saitisfies the criterion of luddit audience.

Any method that can transfer the hyperlink (or Alt/Title as it is already parsed) in the calling statement will do the trick.


----------



## MMJ (Oct 15, 2006)

Mr Red said:


> IE5.5, Opera 5, FF 2 and Moczilla 1.0XXXX are used to verify it saitisfies the criterion of luddit audience.


Woah, browser update time? 

Opera 5 was released *a full 8 years ago*.

v10 should be coming out sometime soon.


----------



## -Fabez- (Jul 28, 2008)

Mmj has a good point, maybe you should ask your target audience to upgrade thier browsers.


----------



## JimmySeal (Sep 25, 2007)

Your page is generating a JavaScript error because your JavaScript file is missing this code:


```
function makeCursorObj(obj,nest){ 
nest=(!nest) ? '':'document.'+nest+'.' 
this.css=bw.dom? 

document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+"document.layers." 
+obj):0; 
this.moveIt=b_moveIt; 
return this 
} 
function b_moveIt(x,y){this.x=x; this.y=y; this.css.left=this.x; 
this.css.top=this.y} 
function move(e){ 
x=bw.ns4 || bw.ns5?e.pageX:event.x 
y=bw.ns4 || bw.ns5?e.pageY:event.y 
if(bw.ie4 || bw.ie5) y=y+eval(scrolled) 
oCursor.moveIt(x+fromLeft,y+fromTop) 
}
```
But you still haven't really told us what you're trying to do. You haven't said when you want these text flags to show up or what you want them to say. You shouldn't expect us to dig through your code to figure out what it is you're trying to do.


----------



## Mr Red (Dec 1, 2008)

all I can do by way of explanation is to re-iterate in a different way.

layer visible with message as the alt/title becomes visible during hover.

Message in layer ideally mimic the alt/title message but at a lager font size. Though a single message of "Post Code Visible" is all I can do at present.

The reason I stick with old browsers is because there are folks out there who do also - they are the lowest common denominator. I know not who they are and I have a certain distaste for sites that assume you can see what they see - like Flash & no skip link & no text only version. 

The missing code has probably been removed because there IE does not handle the tracking of the mouse in the same way as Mozilla based browsers, some functions have yet to be excised where that is a factor though in many cases it is handled by detecting IEX.X and not calling(IE7 is a law unto itself and has a security bug patch as of about 1 month ago). It does not affect the onMouseOver/onMouseOut functions.
Thanks for the consideration - I will go and investigate more. My current version is not posted - I have been through many recently.


----------



## JimmySeal (Sep 25, 2007)

Please give us at least some hint of how you expect the code to behave (aside from what you expect the final result to be). Please name the relevant functions, how the layer is supposed to be generated, etc. As I've said, you cannot expect us to dig through a cryptic 300 line JavaScript file and make sense of the whole thing without any help from you.


----------



## Mr Red (Dec 1, 2008)

same explanation, different words - trial code:

named (id) div layer exists hidden (written in HTML)
onMouseOver shows layer (assigned in JavaScript)
onMouseOut hides layer ditto 
Div layer should show words like "Post Code of venue is _XY1 2PQ_"
where text "_XY1 2PQ_" is unique to each link.

I have tried writing in HTML the code (where showlayer is a function using parameters)

```
<a HREF=............ alt="post code is XY1 2PQ"............ onMouseOver showlayer("XY1 2PQ")> etc </A>
```
 but onMouseOver will not handle parameters. setting the onMouseOver call in JavaScript behaves the same the same. It refuses to call the function and all subsequent JavaScript stops.

The only way I can see to change the text of the layer uniquely is to have a function for each link (there might be 100 on the page). This may be the route I take. My pages are generated in Excel - VBA so I can program file making with the functions in a js file and reference it from HTML. e.g.:


```
<SCRIPT language=JavaScript src="pcodes.js" type=text/javascript>
</SCRIPT>
```
 that way the functions load last or when called so the visible data are seen first.

the brainwave I had was to find out if I could 

```
document.write("<script etc> functions etc </script>")
```
 and I will be trying it - but before I do, has anyone tried writing JavaScript code with JavaScript? And what should I beware of?


----------



## JimmySeal (Sep 25, 2007)

Now we're getting somewhere.

There's no reason why the onmouseover event of a tag shouldn't be able to invoke JavaScript that takes a parameter, but is this the syntax you're using?

...

onmouseover is a tag attribute like any other and must be used with the right syntax:


```
onmouseover="showlayer('XY1 2PQ')"
```
Also, my guess is that you will need some way of telling the method _where_ to display the popup label, but that should be easy enough.

Now if you would just show us the showlayer code you have so far, perhaps one of us can try to get it working.


----------



## Mr Red (Dec 1, 2008)

I tried several permutations of quotes and double quotes.
Maybe because I am covering legacy browsers and restricting it to JavaScript 1.2 it doesn't work but I will try again.

I do have the option of calling simpler functions albeit having to generate multiple unique functions. I am braced for finding limits on storage, and speed. I will be back when I have some progress.


----------

