0

I am working on a data view web part. I am using Java script for some of my functioning and having trouble with calling javascript function with more than one arguments while single argument function is working fine.

When i used this single argument function, it worked fine:

    <script type="text/javascript">
    function PrintElement(loopPosition)
    {
        alert("1");
    }
    PrintElement(<xsl:value-of select="$pos"/>);                    
</script>

Later on, i tried to add one more argument but it is not calling the javascript function and page is giving error on the line where function is being called.

I tried the following but no luck:

PrintElement(<xsl:value-of select="$pos"/>,<xsl:value-of select="$FPageName"/>);
PrintElement(<xsl:value-of select="$pos"/>+","+<xsl:value-of select="$FPageName"/>);
PrintElement("'"+<xsl:value-of select="$pos"/>+"'","'"+<xsl:value-of select="$FPageName"+"'"/>);
PrintElement("'"+<xsl:value-of select="$pos"/>+"','"+<xsl:value-of select="$FPageName"+"'"/>);

First and Second statementdoes not call the function and third throws an error.

Could someone please help me with the exact sysntax and elaborate a bit.

  • PrintElement("'"+<xsl:value-of select="$pos"/>+"','"+<xsl:value-of select="$FPageName" />"'"); should work – Robert Lindgren Jun 3 '13 at 9:44
  • It should but it doesn't – Mohit Jun 3 '13 at 11:43
0

If you want to pass two arguments to a Javascript function, then that function needs to be defined to have two arguments. If it is defined to take only one argument, then, of course it will error.

So, change your Javascript function to accept and process a second argument along the lines of this:

<script type="text/javascript">
    function PrintElement(loopPosition, PageName)
    {
        alert(loopPosition);
        alert(PageName);   
    }
</script>
  • My mistake, I didnt explained properly. Its already there. – Mohit Jun 3 '13 at 11:44
0

Finally, I made it work. It goes like this:

PrintElement('<xsl:value-of select="$pos"/>','<xsl:value-of select="$FPageName"/>');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.