24

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.

1
  • sounds like your variable is expecting a number and it isn't ? What should the variable contain , and how is it calculated? Commented Apr 14, 2009 at 1:41

1 Answer 1

46

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.

Sign up to request clarification or add additional context in comments.

1 Comment

At least you've stayed positive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.