locked
Pass XSL variable to JavaScript function RRS feed

  • Question

  • I want to call a JavaScript function OnClick of a button:

    <button onclick="'javascript: myJSFunction('VAR1')">Do Something!</button>
    
    

    Because this button is in a XSL stylesheet, I want to pass an xsl variable to my JavaScript function:

    <button onclick="'javascript: myJSFunction(<xsl:value-of select="@ID"/>)">Anmelden!</button>
    
    


    But this code is invalid due to the false escaping. I tried nearly everything, with(out) any quotes but without any success.

    How is the correct syntax to pass an xsl variable to my JavaScript function?
    • Edited by Diana.Manow Wednesday, August 12, 2009 2:53 PM
    Wednesday, August 12, 2009 2:25 PM

Answers

All replies

  • That shoud work:

    <button >
    <xsl:attribute name="onclick">javascript: anmelden(
    <xsl:value-of select="@ID"/>,"Seminar XY") </xsl:attribute>
    Anmelden!
    </button>
    



    http://alecpojidaev.wordpress.com
    • Edited by Alec Pojidaev Wednesday, August 12, 2009 2:55 PM
    • Marked as answer by Diana.Manow Wednesday, August 12, 2009 3:00 PM
    Wednesday, August 12, 2009 2:47 PM
  • Thanks a lot that really worked! I was suffering with quotes, escaping and stuff like and then it turns out to be so easy!

    Thanks!
    Wednesday, August 12, 2009 3:00 PM