Take the tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
 
PrintElement("'"+<xsl:value-of select="$pos"/>+"','"+<xsl:value-of select="$FPageName" />"'"); should work –  Robert Lindgren Jun 3 at 9:44
 
It should but it doesn't –  Mohit Jun 3 at 11:43
add comment

2 Answers

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>
share|improve this answer
 
My mistake, I didnt explained properly. Its already there. –  Mohit Jun 3 at 11:44
add comment
up vote 0 down vote accepted

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

PrintElement('<xsl:value-of select="$pos"/>','<xsl:value-of select="$FPageName"/>');
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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