Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,616 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 989 people online right now. Registration is fast and FREE... Join Now!




onMouseOver in xsl

 
Reply to this topicStart new topic

onMouseOver in xsl, generating javascript from xsl

sophe
post 23 Aug, 2006 - 05:09 AM
Post #1


New D.I.C Head

*
Joined: 7 Jul, 2006
Posts: 5


My Contributions


hi all,

i'm extending xsl code that another programmer wrote which generates an html page. i'm trying to get an image to show up when the mouse is over a bit of text.

when i do a simple opperation that doesnt require a seperate function it works:
CODE

<h2><img src="images/menu-option-off.gif" alt="Menu Option"/>
       <a onmouseover="alert('Back to homepage');" >
           .....
       </a>
</h2>


but when i call the same code from a function it doesnt...
CODE

function func() {"alert('Back to homepage')";}
...
<a onmouseover="java script:func();">
...

any ideas?
User is offlineProfile CardPM

Go to the top of the page

Spider
post 23 Aug, 2006 - 04:24 PM
Post #2


Arachnid

****
Joined: 10 Jul, 2002
Posts: 769


My Contributions


try

CODE

function func() {"alert('Back to homepage')";}
...
<a onmouseover="func()">
...


smile.gif
User is offlineProfile CardPM

Go to the top of the page

Arbitrator
post 23 Aug, 2006 - 08:23 PM
Post #3


D.I.C Regular

Group Icon
Joined: 26 Jan, 2005
Posts: 492



Thanked 1 times
My Contributions


Why is the code for your alert() function surrounded by double quotes? You may as well remove the java script: URL scheme since the contents of an onmouseover event are by nature JavaScript, making it redundant. In other words, try this:

java script:
function func() {
  alert("Back to homepage");
  }


HTML:
<a onmouseover="func();"></a>

Note that "java script:" and "JavaScript" should not have any spaces and the latter should have a capital "J" and "S". This forum is doing something messed up to them.
User is offlineProfile CardPM

Go to the top of the page

sophe
post 24 Aug, 2006 - 01:32 AM
Post #4


New D.I.C Head

*
Joined: 7 Jul, 2006
Posts: 5


My Contributions


Thanks ! that did solve it.
i was just using that to learn the principle
my problem now is that i want to do another onmouseover function this time making an image change when some text has the mouse over it...
my code is:
if (document.images) {
img_on =new Image(); img_on.src = "images/menu-option.gif";
img_off=new Image(); img_off.src = "images/menu-option-off.gif";
}

function func() {
if (document.images) document.imgName.src=img_on.src;
}
function func1() {
if (document.images) document.imgName.src=img_off.src;
}


<h2><img name=imgName src="images/menu-option-off.gif" alt="Menu Option" />
<a onmouseover="func();" onmouseout="func1();" >
<xsl:attribute name="href"> <xsl:text>....</xsl:text>
</xsl:attribute>
<xsl:value-of select="title"/>
</a>
</h2>

the problem is that when i put the code as it is the xsl doesnt manage to build the html.
when i surround the img name with quotes (name="imgName") but the mouseover doesnt work.

am i making things too complicated?


-----------------------------
QUOTE(Arbitrator @ 23 Aug, 2006 - 09:23 PM) *

Why is the code for your alert() function surrounded by double quotes? You may as well remove the java script: URL scheme since the contents of an onmouseover event are by nature JavaScript, making it redundant. In other words, try this:

java script:
function func() {
alert("Back to homepage");
}


HTML:
<a onmouseover="func();"></a>

Note that "java script:" and "JavaScript" should not have any spaces and the latter should have a capital "J" and "S". This forum is doing something messed up to them.
User is offlineProfile CardPM

Go to the top of the page

Arbitrator
post 26 Aug, 2006 - 12:57 AM
Post #5


D.I.C Regular

Group Icon
Joined: 26 Jan, 2005
Posts: 492



Thanked 1 times
My Contributions


QUOTE(sophe @ 24 Aug, 2006 - 02:32 AM) *
my problem now is that i want to do another onmouseover function this time making an image change when some text has the mouse over it...

the problem is that when i put the code as it is the xsl doesnt manage to build the html.
when i surround the img name with quotes (name="imgName") but the mouseover doesnt work.

am i making things too complicated?
The first part of your code is to preload images and the last part is XSL, a language I'm unfamiliar with; I'm not going to get into those and they're omitted from the following code.

I will tell you that quotation marks around attribute values are required in XML/XHTML and that the name attribute is deprecated in XHTML 1.0 Strict; the modern attribute is id and the corresponding JavaScript reference is getElementById(). So…

JS:
function imgOver() {
  document.getElementById("imgName").src = "images/menu-option.gif";
  }
function imgOut() {
  document.getElementById("imgName").src = "images/menu-option-off.gif";
  }


XHTML:
<img id="imgName" alt="Menu Option" src="images/menu-option-off.gif"/>
<a onmouseover="imgOver();" onmouseout="imgOut();">[…]</a>


Note that you may need to escape the forward slashes in the JavaScript image URLs by placing a backslash in front of them. If it doesn't work, try that.
User is offlineProfile CardPM

Go to the top of the page

sophe
post 4 Sep, 2006 - 01:26 AM
Post #6


New D.I.C Head

*
Joined: 7 Jul, 2006
Posts: 5


My Contributions


Thanks all, but i think the problem is with the xsl side so i've handed it over to the original developer.....
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 03:04AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month