Jump to content

To send variables from template to javascript


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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...