By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,607 Members | 1,982 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,607 IT Pros & Developers. It's quick & easy.

newline in browser window text

P: 6
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?
Mar 21 '12 #1
Share this Question
Share on Google+
9 Replies

Expert Mod 5K+
P: 8,639
should i be using something else?

hint: look into the HTML specification.
Mar 21 '12 #2

P: 6
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 ";
  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. }
  16. answerText=answerText+"\nYour total score is : "+score+"\n";
  18. //now score the user
  19. answerText=answerText+"\n Comment : ";
  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. }
  41. answerText=answerText+"Hit the back button to go back to the test then hit the clear button to start over.";
  45. document.write(answerText);
  47. //alert(answerText);
  48. }
Mar 21 '12 #3

Expert Mod 5K+
P: 8,639
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

P: 6
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

Expert Mod 5K+
P: 8,639
I would be interested to have a look at that particular code.
Mar 21 '12 #6

P: 6
i gave you the code in previous reply
Mar 21 '12 #7

Expert Mod 5K+
P: 8,639
there is no <br> in your previous reply.
Mar 21 '12 #8

P: 6
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

P: 6
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

Post your reply

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