views:

91

answers:

4

I would like to convert a numerical value to a text string. I am opening several windows with the window.open() command and I would like these windows not to be on top of each other.

For that I use the argument "left" and "top" in the windows.open command but these parameters need to be text entities.

for (var i = 0; i < final_number; ++i )
{
    left_value=50+(50*i);
    list[i]=window.open(url[i],"","height=500,left=left_value,width=1000");
};

When calculating left_value=50+(50*i), the result is numerical.

The problem is that the window.open() command is expecting a text parameter for left_value.

I thus want to convert left_value from X to "X"

+1  A: 

Use string concatenation:

'height=500,width=1000,left=' + left_value
strager
It worked! Thanks!
+5  A: 

You can construct a string using the plus operator:

for (var i = 0; i < final_number; ++i ) { 
   left_value=50+(50*i); 
   list[i]=window.open(url[i],"", "height=500,left="+left_value+",width=1000"); 
};

Also, I would suggest using a tool like the firefox plugin firebug to help debug your javascript.

Jon Hoffman
It worked! Thanks!I do have firebug. I don't quite know how to use it for JS debugging though. Any recommendation to get me started?
yea, if you activate and click on the console tab there should be an area on the right where you can actually enter javascript and run it. Recommended reading: http://getfirebug.com/docs.html
Jon Hoffman
A: 

For a simple conversion to a string you can use:

strvalue = String(value)

But usually explicit conversions like this are not needed since javascript does automatic type conversions when appropriate.

sth
+1  A: 

You can use following string conversion to convert number to string

var intValue=4;
intValue= ''+intValue;

in first statment intValue is of type long and then it will be converted to string. Hope this will help.

Asim Sajjad