Escape Characters for Prompt Boxes San Jose CA

Would you like single and double quotes, tabs, returns, or double spacing in your Alert and Prompt boxes? Yes? Then click for this one.

Local Companies

Epoch Software Systems Inc
(408) 432-3110
2680 N 1st St
San Jose, CA
Zamora Maria
(408) 297-3650
621 Tully Rd
San Jose, CA
Dorian Does It All
(408) 265-8119
San Jose, CA
Ebd
(408) 279-7125
2 N 1st St
San Jose, CA
Magma Design Automation
(408) 565-7500
1754 Technology Dr
San Jose, CA
Misha Consulting Corp
(408) 279-7125
2 N 1st St
San Jose, CA
Pacific Data Management Inc
(408) 283-5900
111 N Market St
San Jose, CA
Umanage Technology
(408) 451-8464
50 Airport Pkwy
San Jose, CA
Sonoa Systems
(408) 748-1730
3255 Scott Blvd
San Jose, CA
Iota Technology Inc
(408) 428-9898
2635 N 1st St Ste 115
San Jose, CA

provided by: 
Originally published at Internet.com


...use these to jump around or read it all
[The Prompt Example] [The Alert Example]
[The document.write Example]

I get letters now and again asking how people are able to create such great looking alert and prompt boxes. Readers want to know how people get line breaks and double and single quotes to show up so nicely.

This also translates to any JavaScript commands that write to the page, including the document.write command. I know you've hit this wall. You write a script and you'd like to put in a single quote as in the word "you'll" or "you're". YOU know it's just a single quote but the darn JavaScript thinks it's the end of the line. Ugh! When will they build a computer that can read our minds? Is that too much to ask?

I guess it is. Until the mind-reading computers come out, using a single quote in a JavaScript line means one thing...Error!

But fear not. Learn these few simple escape characters and you'll be well on your way to putting quotes, returns, and tabs all over the JavaScript place.

-----------------------------------

The Prompt Example

Let's do the prompt first. I made it pretty small on text. Click the button to trigger the prompt to show up.

Hopefully you can scroll this page and show the code that created the text while at the same time showing the prompt box. That'll help greatly when you see the code:

var name = prompt("Please write your \'name\' in the box\r
Write it with \"quotes\" like this.","");

(this should be all on one line)

Look closely. You'll notice the single quotes were created with this: \'

The return was created with this: \r

The double quote was created with this: \"

The backslash is the key. If you plop that in front of the quotes or the letter "r" you escape the coding long enough for the script to understand you want the character to represent text rather than a command to be used in the coding. That's why we call it an escape character. Get it?

I have another similar tutorial on this topic regarding tabs. There's no real method of getting tabs in HTML. You need to use a table to get the nice columns. Well, if you use the escape character \t and write the text using a document.write method, you'll get the tabs. You can see the tutorial here.

I'll show a quick example using document.write later on in this tutorial. Now on to the Alert example.

-----------------------------------

The Alert Example

I used all four escape characters in this example. Note I sometimes used two to get a double tab or a double return. Position the scroll of the page so that the code is at the bottom and you can look at the alert box at the same time. Once you have that, click the button.

Now here's the code. This should all be written on one long line. It's probably trancating on your screen though. Just make a point of going through it piece by piece and you'll see each of the escape characters at work.

alert('OK Then!\r\rYou want a neat box like \"this\" one?\r\rWell!\r\rYou\'ll need:\rBrains\tBeauty\t\tTalent\rMoney\tDog food\t\tLuck\rA Cat\tEye of Newt\tA Shrubbery!\r\rAnd the ability to \'read\' this tutorial.\r\rOK?')

Get it?

-----------------------------------

The document.write Example

You wouldn't want to use the retun character in a document.write because it's better to literally write a BR or P tag to the page. Where these escape characters come in real handy is when you need to use a double or single quote yet you do not want to end the line. For example, the line just below this one was written with a document.write command:

Anybody else have parents that sounded like that? Mine did. It was the only sentence I could think of that had a single and double quote in it. Huh. I guess I have issues to work out. Here's the code:

Read slowly and pick out the escape characters.

-----------------------------------

That's That

I'll bet those little blips of information just made someone's life a little easier. At least now we'll have less alert boxes that do not talk in contractions.

Enjoy!

[The Prompt Example] [The Alert Example]
[The document.write Example]

Author: Joe Burns

Read article at Internet.com site

Featured Local Company

Virgance Activism 2.0

(415) 290-0787
164 South Park St.
San Francisco, CA

Related Local Events
STREAMING MEDIA WEST 2009
Dates: 11/17/2009 - 11/19/2009
Location: San Jose McEnery Convention Center
San Jose, CA
View Details

GRID 2009
Dates: 9/1/2009 - 9/1/2009
Location: IEEE
Palo Alto, CA
View Details

Search Engine Strategies San Jose Conference and Expo
Dates: 8/11/2009 - 8/14/2009
Location: San Jose McEnery Convention Center
San Jose, CA
View Details

Search Engine Strategies San Jose Conference & Expo
Dates: 8/10/2009 - 8/14/2009
Location: San Jose McEnery Convention Center
San Jose, CA
View Details

VMware Virtualization Forum 2009
Dates: 7/23/2009 - 7/23/2009
Location:
Palo Alto, CA
View Details