views:

45

answers:

2

Hi,

I'm taking some information from some variables I have already defined outside this function to create a html svg text box.

Here is the function which is causing me trouble:

 RenderTextBox:function()
{
  alert('this.x: ' + this.x);
  alert('this.y: ' + this.y);
  this.textBox = paper.text(this.x, this.y, this.htmlTextBox);
 }

The alerts works prefectly, and prompt me with the values expected. However, the final line which is supposed to create the text box puts them nowhere to be seen. Does anybody know why?

If I replace 'this.x, this.y..' with numerical values in the final line of the function, the text box is placed correctly. It's only when I use the 'this.x' and 'this.y' that I have issues.

+4  A: 

Hi,

Sometimes numerical values are converted in strings. That's one of the very bad point about javascript : variables are not needed to be typed.

You should try to parse them as int in order to make them react as integers again : http://www.w3schools.com/jsref/jsref_parseInt.asp

Kaaviar
+1, but also follow Doug Crockford's advice and always include the radix (10 if you're working in base-10).
Skilldrick
A: 

Wild Guess: an you try putting this.x and this.y into variables and then passing these variables to the function call in the last line?

Something like:

var tx = this.x;
var ty = this.y;
this.textBox = paper.text(tx, ty, this.htmlTextBox);
Nivas
that is equivalent to the OP's snippet.
Chii