Jump to content

To send variables from template to javascript


elcaiaimar

Recommended Posts

Hello,

 

I've a problem when I try to send variables (django variables) from html to javascript. My variables contain coordinates, I mean, they are decimals, and when I receive them in the javascript and I show them in console, I've got only the no decimal part of the coordinates. This is my code:

Template:

<td><button onclick="window.to('{{p.coorx}}','{{p.coory}}')" data-coorx="{{p.coorx}}" data-coory="{{p.coory}}">Ver Pozo</button></td> 

Javascript:

window.to = function(coorx,coory) {  var coorx = parseFloat(coorx);  var coory = parseFloat(coory);  console.log(coorx);  console.log(coory);}

I'm sure that my error is in the way in what I establish the parameters to send in HTML. I've tried several choices as:

<td><button onclick="window.to(" + {{p.coorx}} + "," + {{p.coory}} + ")" data-coorx="{{p.coorx}}" data-coory="{{p.coory}}">Ver Pozo</button></td> 

But then it gives me an error: Uncaught SyntaxError: Unexpected token }

 

Would anybody know how to solve this problem?

 

Greetings and thank you very much in advance!

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...