0

I have the following javascript code:

var result = ("Please enter your name","Andrew");

and i wanted to underline the word "name" in the above message.

This is trivial but i have no clue after searching for escape code representation for underline. Or is the above possible in javascript ?

4
  • 3
    The code doesn't make sense. It's equivalent to var result = "Andrew";, the first string is just discarded. Besides, any formatting like underlining depends on how you display the message, so you have to specify that also. Commented Jul 29, 2011 at 2:15
  • A demo of Guffa's comment: jsfiddle.net/Fw9RX Commented Jul 29, 2011 at 2:17
  • Maybe this is just a simplified example, but why do you want to underline "name"? Do you find a lot of users misread the question and enter their favourite colour? Commented Jul 29, 2011 at 2:24
  • he probably mean to put square bracket [ .. ] instead of the (...) Commented Jul 29, 2011 at 2:28

3 Answers 3

2

If the example code given had a typo and should've read like this:

var result = window.prompt("Please enter your name","Andrew");

then the answer is that you can't format the text or change the labels on the buttons or anything. This applies to the built-in alert() and confirm() as well as to prompt().

It's a bit more work, but you can implement your own equivalent dialog by building one from HTML using a transparent <div> to cover the rest of your page so that users can't interact with the rest of the page until the dialog closes. (Or use a translucent <div> to make it more obvious to the user that the rest of the page is "disabled".)

I would not bother coding this from scratch when there are lots of JS libraries that do it for you. The jQuery dialog is pretty easy to use, to name just one option.

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

1 Comment

Thanks. Will explore jQuery dialog on this.
1

If this is ending up on a web page you should just be able to use:

var result = ("Please enter your <u>name</u>","Andrew");

...but I'm not exactly sure what it is you're intending to do. Can you add more detail to your question?

3 Comments

Note: The u tag is deprecated in HTML 4.
I made a typo error. It should be : var = prompt("Please enter name","Andrew"); I gotten the answer. The prompt cannot support display of underline.
Ah... I thought there was something missing there. Yea, if you want a custom prompt, you'll have to make your own.
1
var result = ("Please enter your <u>name</u>","Andrew");

2 Comments

Note: The u tag is deprecated in HTML 4.
Thanks everyone for the help. It is a typo, what i meant is the following

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.