473,419 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

Linebreak In JavaScript

I have these line of javascript:



Expand|Select|Wrap|Line Numbers
  1. $(document).ready(function () {
  2.     /*$('#first').focus();
  3.     $(this).keyup(function (e) {
  4.         if (e.keyCode == 13) {
  5.             generate();
  6.         }
  7.     });*/
  8.         });
  9. function generate() {
  10.     if($("input[name='name']").val().length > 1) {
  11.         fi = $("input[name='name']").val().substring(0,1).toUpperCase();
  12.         var sl = ["Cool "];
  13.         var sl2 = ["Hand "];
  14.         var sl3 = ["Luke",];
  15.  
  16.         {
  17.             var i = Math.floor(Math.random() * sl.length);
  18.             var j = Math.floor(Math.random() * sl2.length);
  19.             var k = Math.floor(Math.random() * sl3.length);
  20.             var nick = sl[i] +   sl2[j] +   sl3[k];
  21.         }
  22.         {
  23.         $("#answer").text("Your Name Is: " +nick);
  24.         $("#answer").fadeIn("slow");
  25.         } 
  26.     }
  27. }


I would like for it to return:

Your Name Is:
Cool Hand Luke


I want the "Cool Hand Luke" to be on a separate line but I don't know how to put a linebreak in the .text string. Is this something somebody could tell me how to do?
Mar 10 '12 #1
3 1983
Dormilich
8,658 Expert Mod 8TB
since you want to output HTML, you would use a HTML break (<br>)
Mar 11 '12 #2
Thanks for the response Dormilich

Where in the line:
Expand|Select|Wrap|Line Numbers
  1. $("#answer").text("Your Name Is: " +nick);
Do I put (<br>)
Mar 12 '12 #3
Dormilich
8,658 Expert Mod 8TB
where would you put it?
Mar 12 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: nAmYzArC | last post by:
Hi everyone, I'm setting the body of an email using values from a form firstname = bob lastname = dole ebody = 'First Name: ' + firstname + '\r\n' + 'Last Name: ' + lastname ...
1
by: Lucie | last post by:
Hi, I've created a form with 2 dialoglist fields: 1 state and 1 city. I want to select a state, and I need a way to build the city list. In order to do this, I've used the onChange event (on the...
4
by: Dirk Reske | last post by:
Hey, I have following struct: struct Packet { string Command; byte data; }
2
by: Georg Weiler | last post by:
Hi, I have a form, where the user enters text. After submit, the text is then inserted into a PostgreSQL database. So far, so good. The problem is, that most of my users copy&paste their text...
17
by: Chris Ianson | last post by:
Hi, I have this JavaScript, which I only want to occur if a user clicks on a hyperlink hotspot in a large image: <script type="text/javascript"> <!-- var answer = confirm ("This link is not...
2
by: Shirenseru | last post by:
Hello guys, i hope you can help me with this cause it's driving me crazy! I got the following statement in JavaScript: if(currTotal < 27{document.getElementById('isResult').innerHTML =...
3
by: Michael Hamm | last post by:
My page http://www.math.wustl.edu/~msh210/whatsnew.xml (with XSLT and CSS adding formatting) has a paragraph-type break after "Subscribe to this feed" which, afaIct looking at the source code,...
3
by: Per W. | last post by:
Hi, is it possible to have Literal using linebreaks? If i have a textfile with more than 1 line then Literal take all on one line. /Per W.
1
by: chadlupkes | last post by:
On this page, and others like it: http://46dems.com/larc/contact.previewtest.php I have a preview function: function PreviewButton_onclick() { var messagesubject = "Subject: " +...
2
by: wannasee | last post by:
Hello everybody, I am new at javascript and I would like to write a script that resizes the input fieds of an html table depending on the entered text. The input fields are placed in table cells...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.