newline in browser window text

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • siobhanh
    New Member
    • Mar 2012
    • 6

    newline in browser window text

    when i use the new line characters (\n) in my text (i.e. answerText=answ erText+"\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
    Last edited by acoder; Mar 21 '12, 01:33 PM.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    should i be using something else?
    obviously.

    hint: look into the HTML specification.

    Comment

    • siobhanh
      New Member
      • Mar 2012
      • 6

      #3
      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.

      Code:
      function Score(){
      var answerText = "How did you do? \n ------------------------------------ \n ";
      for(i=1;i<=20;i++){
         answerText=answerText+" \n Question "+i+" :\n ";
      	 
        if(ans[i]!=yourAns[i]){
          answerText=answerText+"The correct answer was "+ans[i]+"\n"+explainAnswer[i]+"\n";
        }
        else{
      	  answerText=answerText+"Correct!";
         // answerText=answerText+"\n Correct! \n"+explainAnswer[i]+"\n";
          score++;
        }
      }
      
      answerText=answerText+"\nYour total score is : "+score+"\n";
      
      //now score the user
      answerText=answerText+"\n Comment : ";
      
      if(score<=0){
      answerText=answerText+"You did not answer any of the questions. "; 
      }
      else
      if(score>=1 && score <=17){
      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.";
      }
      else
      if(score==18){
      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."; 
      }
      else
      if(score==19){
      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.";
      }
      else
      if(score==20){
      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.";
      }
      
      answerText=answerText+"Hit the back button to go back to the test then hit the clear button to start over.";
      
      
      
      document.write(answerText);
      
      //alert(answerText);
      }

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        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?

        Comment

        • siobhanh
          New Member
          • Mar 2012
          • 6

          #5
          I tried to insert a <br> and it caused the program not to work so I assumed i couldn't do it.

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            I would be interested to have a look at that particular code.

            Comment

            • siobhanh
              New Member
              • Mar 2012
              • 6

              #7
              i gave you the code in previous reply

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                there is no <br> in your previous reply.

                Comment

                • siobhanh
                  New Member
                  • Mar 2012
                  • 6

                  #9
                  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.

                  Comment

                  • siobhanh
                    New Member
                    • Mar 2012
                    • 6

                    #10
                    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)!

                    Comment

                    Working...