views:

600

answers:

1

For javascript prompt:

prompt("Message", "default value in the text field");

is it possible to add a variable into the default value?

For example:

var default = 'default value';
prompt("Message", +default+"and other values");

The above example doesn't work as it shows 'NaN and other values' in the text field. I want the field to show 'default value and other values'. I'm wondering what's the right way to do it.

+2  A: 

Stupid me. Here's the solution:

var default = 'default value';
prompt("Message", default+"and other values");

There was a leading plus before the default variable.