Atlas
Atlas

Reputation: 71

A bug in JavaScript

I'm having trouble finding a bug in my JavaScript code. It tells me a runtime error has occurred: 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?

Upvotes: -1

Views: 179

Answers (3)

RoToRa
RoToRa

Reputation: 38400

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>")

Upvotes: 0

Moncader
Moncader

Reputation: 3388

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>")
    }

Upvotes: 0

Pekka
Pekka

Reputation: 449395

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>")

Upvotes: 10

Related Questions