views:

83

answers:

3

Dear all,

I have trouble to figure out a bug in javascript. It sounds so simple though to debug, but I could not find out. It tells me a runtime error has occured ...Expected')'

here is the code:

 <xsl:for-each select="./projects/project">                     
    <script LANGUAGE='Javascript'>                  
    x = 0;
    if(x==0){
    document.write("<td style="background-color:#76787A" ><xsl:value-of  select="weight"/></td>")
    }
    else
    {
    document.write("<td><xsl:value-of select="weight"/></td>")
    }
    </script>                       
 </xsl:for-each>

what do you think?

+10  A: 

You are not escaping your strings properly. If you look closely, the syntax highlighting here on SO shows you the problem.

Use escaped \" or single quotes ' when using quotes inside a string.

document.write("<td style='background-color:#76787A' >
                <xsl:value-of  select='weight'/></td>")
Pekka
+1  A: 

Look at your document.write calls. You have a string (inside the " ") that again has " " inside of it. To Javascript this means you are closing the string, then have nonsense text to javascript, then opening the string again, etc.... You need to escape your string with a backslash like this:

document.write("<td style=\"background-color:#76787A\" ><xsl:value-of  select=\"weight\"/></td>")
    }
Moncader
+1  A: 

You need to escape the quotes in the String, or they aren't in the strings but terminating them.

document.write("<td style=\"background-color:#76787A\" ><xsl:value-of  select=\"weight\"/></td>")
RoToRa