When you display a long text string in an alert box, it creates an unappealing too wide message box. You can improve the aspect ratio of the message box by placing newline (\n) character escape sequences within the string to explicitly define where the string should break to create a new line.
Welcome to Bucaro TecHelp!

Welcome to Bucaro TecHelp!
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

[About BTH]  [User Agreement]  [Privacy Policy]  [Site Map]  [Contact Form]  [Advertise on BTH]  [News Feed]

Google
Web
This Site
   WARNING!
What you learn from these Totally FREE
Einstein Newsletters could cause your friends to mistake you for someone else!
  [] automobiles
  [] business
  [] parenting
  [] computers
  [] contests
  [] education
  [] entertainment
  [] food/wine
  [] free stuff
  [] genealogy
  [] health/fitness
  [] home/garden
  [] humor
  [] marketing
  [] investing
  [] pets
  [] inspiration
  [] self-improve
  [] recreation
  [] travel
  [] womens stuff
  [] writing/reading
Click here and choose as many as you like!

Define Lines in a String

You know that to define a String in Java Script requires that you enclose the data within quotes. For example, the statement below displays a string (the first line in Abraham Lincoln's in the Gettysburgh address) in a message box.

alert("Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.");

(code required to be on one line.)

Message box too wide

As you can see above, this creates an unappealing too wide message box. We can improve the aspect ratio of the message box by placing newline \n character escape sequences within the string to explicitly define where the string should break to create a new line, as shown below.

alert("Four score and seven years ago our fathers\n brought forth on this continent, a new nation,\n conceived in Liberty, and dedicated to the\n proposition that all men are created equal.");

(code required to be on one line.)

More appealing message box

This creates the more appealing message box shown above.

-  If you want to format your code so that it has the same line structure as that displayed in the message box, enclose each line in quotes and use the string concatenation operator to rejoin the lines, as shown below.

alert("Four score and seven years ago our fathers\n" + "brought forth on this continent, a new nation,\n" + "conceived in Liberty, and dedicated to the\n" + "proposition that all men are created equal.");

This makes your code more neat and more understandable.

Web Design Sections

RSS Feed RSS Feed

Java Script Quick Reference
Java Script Data Types
Java Script Reserved Words
Java Script Arithmetic Operators
Comparison Operators
Java Script Arrays
Java Script Character Encoding and Decoding
The if/else Structure
The switch/case Structure
The for Loop
The while Loop
The break Statement
The continue Statement
JavaScript Math Object
Round a Number
Determine Absolute Value
Determine Minimum and Maximum
Generating Random Numbers
Java Script Trigonometric Methods
Java Script Number Object
Format a Number as Currency
Java Script Strings
Compare Two Strings
Find a Character or a Substring Within a String
Include a Quote Character in a String
Include a Backslash Character in a String
Define Lines in a String
Use Escape to Replace Dangerous Characters
Convert a Number to a String
Convert a String to a Number
The Document Object Model (DOM)
Accessing Web Page Elements
Interactively Set Webpage Colors
Get Webpage File Date and File Size
Dueling Windows
Cookie Power Made Easy

Get paid cash typically $4 to $25 for each survey you complete!

[Site User Agreement]  [Advertise on This site]  [Search This Site]  [Contact Form]
Copyright©2001-2007 Bucaro TecHelp P.O.Box 18952 Fountain Hills, AZ 85269