javascript prompt - adding variable in default text

John See picture John See · Apr 14, 2009 · Viewed 18.1k times · Source

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.

Answer

John See picture John See · Apr 14, 2009

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.