Hemang
Hemang

Reputation: 85

Javascript function call from Jade template is not Working

I want to call javascript function from my JADE template. I tried solutions posted in forum. but still it gives me error like "undefined is not a function"

My Javascript function is

 script.
   function addCommas(nStr) {
               return nStr;
       }

And i am calling this function from JADE template like -

 td(style='width: 10%;') #{addCommas("12345")}

But i throws error as below -

undefined is not a function

Can anyone help me on this?

Thanks.

Upvotes: 1

Views: 5328

Answers (1)

stdob--
stdob--

Reputation: 29172

This template code adds a function to call in javascript on the client side:

  script.
      function addCommas(nStr) { return nStr; }

But this template code call a function on the server side but they undefined (according to the previous):

td(style='width: 10%;') #{addCommas("12345")}

So, if you want define and call fuction on the server side you need define a template for another her:

- function addCommas(nStr) { return nStr; }

If you want to call this function on the client side, then leave it in the same definition, but it causes so for example:

script.
  console.log( addCommas("12345") );

Upvotes: 1

Related Questions