Masiar
Masiar

Reputation: 21352

jade not executing javascript functions

I have this jade file

- if (transactions != "")
    table
        th Site Name
        th Deadline
        th Delete Transaction

        each item in transactions
            tr
                td= item.item_name
                td
                    span(id='countdown'+item.timeout)= item.timeout
                td
                    span(style='cursor: pointer;', onclick='deleteTransaction('+item.uniqueId+')')= "X"

    button(id='confirmButton', onclick='confirm();', value="Confirm", name="Confirm")= "Confirm"
    script
        fillCountdown(transactions);

I don't understand why the function fillCountdown in the last line is never called. I have to say that this page is loaded in a Chrome extension, in the popup, but I guess nothing changes.

Can someone help me? Thanks.

Upvotes: 0

Views: 5700

Answers (1)

keviv
keviv

Reputation: 131

The problem seems to be the indentation used in jade. After the script tag, you need to give two spaces indentation and then define the function. For e.g.:

body
  script(type='text/javascript')
    function something() {
    alert("Inappropriate Value")
    }

Also check if the script tag is properly indented with the body tag. If you are defining a function inside the script tag, check the script tag is at only one level indentation with the body tag.. In your code snippet it is not clear if the script tag is nested inside the "if" case or properly aligned with the body tag. When I copied your code snippet, your function "fillCountdown" was indented with 4 spaces with the script tag. In jade the indentation is of two spaces.. Hope this solves your problem.

Upvotes: 3

Related Questions