Click to See Complete Forum and Search --> : Javascript in XSL - Error: function not defined


buzzfever
08-21-2008, 12:01 PM
I've got my javascript in my xsl file like so:


<script type="text/javascript" language="javascript">
<xsl:comment><![CDATA[
....
]]></xsl:comment>
</script>

Then later in my xsl file I have an event that calls a javascript function:


<img src="/btn_buy.gif" alt="Buy!" >
<xsl:attribute name="onmouseover">
dropdownmenu(this, event, menu1, '140px', 'Common Market','Black Patch War')
</xsl:attribute>
<xsl:attribute name="onmouseout">
delayhidemenu()
</xsl:attribute>
</img>

I can see the Buy image and in Firefox's Error Console I get these errors: dropdownmenu is not defined and delayhidemenu is not defined. I've pulled out the Javascript and tested it in an HTML file and it works fine. So I'm guessing it's the xsl file's problem.

Any ideas? Thanks.

randal
11-25-2008, 06:13 AM
I ran into the same problem. I could see the div contents change via innerhtml to include my Javascript code but FF still said 'function not defined'

So, found this Web-site which had a working example on how to load pages via AJAX with javascript inside them

http://www.salix.gr

The idea is to split your javascript code from your xhtml. So your javascript goes through the eval function and the xhtml goes through the innerHTML.

you also need to build your functions so that they attach to the window handler :

myclickfunction = function(){
alert('TEST');
}

RATHER THAN

function myclickfunction(){
alert('TEST');
}


Dan