PDA

View Full Version : Call javascript function with parameter using XSLT



beezleboss
25 Jan 2010, 12:42 PM
I'm having trouble getting my head around XSLT. I am creating an html table and filling it with the xml data using jascript.

i have it basically working but the next thing I want to do is call a javascript function and pass it one of the xml values as a parameter.

I'm trying it with a very simple class at the moment to see if I can get it to work; this is my code.

Function:


function loadMsg(mId)
{
alert(mId);
}


XSLT (snippet):


<tr class="msgListItem" onmouseover="style.backgroundColor='#ff0000';"
onmouseout="style.backgroundColor='#ffffff';"
onclick='loadMsg(<xsl:value-of select="mailid"/>);'>


I know everything works as expected when I do:


<tr class="msgListItem" onmouseover="style.backgroundColor='#ff0000';"
onmouseout="style.backgroundColor='#ffffff';"
onclick='loadMsg("some text");'>




anyone have any ideas?

thanks

dmcleary
26 Jan 2010, 12:21 PM
Hi beezleboss,

I'm not an expert on this but shouldn't you put the XSL value in some kind of quotes? It looks to me like you're telling javascript that <xsl:value-of select="mailid"/> is a variable.

Just my passing comment ... hope it works out for you.

Regards,

David