473,397 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,397 software developers and data experts.

newline in browser window text

when i use the new line characters (\n) in my text (i.e. answerText=answerText+"\n Comment : ";) it works in an 'alert' statement but it doesn't do anything if i write to a browser window? should i be using something else?
Thanks
Mar 21 '12 #1
9 1724
Dormilich
8,658 Expert Mod 8TB
should i be using something else?
obviously.

hint: look into the HTML specification.
Mar 21 '12 #2
the problem is that the answerText is being built in a function so i can't insert HTML code. I borrowed this program and am a little over my head trying to modify it. I am trying to use document.write instead of the alert.

Expand|Select|Wrap|Line Numbers
  1. function Score(){
  2. var answerText = "How did you do? \n ------------------------------------ \n ";
  3. for(i=1;i<=20;i++){
  4.    answerText=answerText+" \n Question "+i+" :\n ";
  5.  
  6.   if(ans[i]!=yourAns[i]){
  7.     answerText=answerText+"The correct answer was "+ans[i]+"\n"+explainAnswer[i]+"\n";
  8.   }
  9.   else{
  10.       answerText=answerText+"Correct!";
  11.    // answerText=answerText+"\n Correct! \n"+explainAnswer[i]+"\n";
  12.     score++;
  13.   }
  14. }
  15.  
  16. answerText=answerText+"\nYour total score is : "+score+"\n";
  17.  
  18. //now score the user
  19. answerText=answerText+"\n Comment : ";
  20.  
  21. if(score<=0){
  22. answerText=answerText+"You did not answer any of the questions. "; 
  23. }
  24. else
  25. if(score>=1 && score <=17){
  26. answerText=answerText+"Refresher Needed! It is strongly recommended that you review the answers to the questions that were missed, before beginning the interview process. For additional information about the the employment process, please contact the Department of Human Resources Management, Employment Services at 792-2240.";
  27. }
  28. else
  29. if(score==18){
  30. answerText=answerText+"Good! You missed a few questions. But you may wish to review the answers to the questions that were missed, before beginning the interview process. For additional information about the employment process, please contact the Department of Human Resources Management, Employment Services at 792-2240."; 
  31. }
  32. else
  33. if(score==19){
  34. answerText=answerText+"Good! You missed a few questions. But you may wish to review the answers to the questions that were missed, before beginning the interview process. For additional information about the employment process, please contact the Department of Human Resources Management, Employment Services at 792-2240.";
  35. }
  36. else
  37. if(score==20){
  38. answerText=answerText+"Congratulations! You correctly answered all of the questions. You possess a good understanding of the general legal considerations of the interview process. For additional information about the employment process, please contact the Department of Human Resources Management, Employment Services at 792-2240.";
  39. }
  40.  
  41. answerText=answerText+"Hit the back button to go back to the test then hit the clear button to start over.";
  42.  
  43.  
  44.  
  45. document.write(answerText);
  46.  
  47. //alert(answerText);
  48. }
Mar 21 '12 #3
Dormilich
8,658 Expert Mod 8TB
the problem is that the answerText is being built in a function so i can't insert HTML code.
care to explain why exactly you can't insert HTML code?
Mar 21 '12 #4
I tried to insert a <br> and it caused the program not to work so I assumed i couldn't do it.
Mar 21 '12 #5
Dormilich
8,658 Expert Mod 8TB
I would be interested to have a look at that particular code.
Mar 21 '12 #6
i gave you the code in previous reply
Mar 21 '12 #7
Dormilich
8,658 Expert Mod 8TB
there is no <br> in your previous reply.
Mar 21 '12 #8
oh sorry. I had taken it out. could you give me an example of how it would work. i will be back tomorrow. thank you.
Mar 21 '12 #9
i'm sorry, the <br> did work when I tried it again this morning. I must have had it in the wrong place the first time. Thank you for you help (and your patience)!
Mar 22 '12 #10

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

Similar topics

3
by: Shiperton Henethe | last post by:
Hi Can anyone tell me how to open up a new normal, full-sized browser window from a small popup window? I'm using something like this. <script language="javascript"> <!--
4
by: metalseb | last post by:
Hi folks I built up a small website which is designed for 800x600 display. Runs just fine in this resolution but if you have a system in 1024 or 1280 pixels wide, the site just "sticks" in the...
4
by: Ed | last post by:
I am building a glossary. Each letter of the alphabet has its own HTML page, and each glossary entry on the page already has a unique HTML anchor tag immediately to the left of it. I've already...
33
by: randau | last post by:
Linking to a Targeted Browser Window I'd like to open reference links to other web sites in a separate browser window from the browser window hosting my own web site pages. The Link Target...
2
by: buran | last post by:
Dear ASP.NET Programmers, I am using the following code block to navigate to the invoice page of my app. when users click on the button btnInvoice. However, I want to display the invoice page in...
6
by: shil | last post by:
I have a server side button that needs to do some preperation and afterwards, if everything goes well, open a new browser with a specific url. I know how to execute javascript from a server side...
3
by: sohan | last post by:
hi I have hyperlink column in a datagrid. The column contains the name of a text file. I am able to appendthe full path of the file. The file is on D drive on the server. But on clicking on...
17
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I find the size of a browser window?...
6
by: bushi | last post by:
hi everyone! i have diplayed my hyperlinks in a iframe.when i redirect to next page.the next page also open in the same frame,but i want to open a new browser window,when i click on the...
4
by: sid | last post by:
"about:blank" oepns new browser window I am writing a webpage that will run on other machines that I may or may not know about. My page is framed where frame1 controls the content of frame2. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.