×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Problem with the out.write function

Problem with the out.write function

Problem with the out.write function

(OP)
Hi!

I have a problem with the out.write(String) function. I use Javascripts on the client side that are somewhat generated by a JSP page. Simplified example:

<script>
   document.all.divTest.body.innerHTML = ' <% out.write(strTest); %>'
</script>


This works fine when strTest is a short string like "Hello World", but it will not work if it includes when it includes linebreakes etc. Then the client script looks something like this:

<script>
   document.all.divTest.body.innerHTML = '<table><tr>
     <td>Test</td>
     </tr></table>'
</script>


which obviously generates an error. Can anyone think of a good solution to this problem. Thanks!

Galilee

RE: Problem with the out.write function

Galilee,

> which obviously generates an error

It's not obvious! Did the result of your out.write() call not produce the expected text in the html file?

If you are using JSP then you might want to do this:

<script>
   document.all.divTest.body.innerHTML = "<%=strTest%>"
</script>

But I don't believe it solves whatever problem you are having.

-pete

RE: Problem with the out.write function

(OP)
It obviously generates an error because a string can span multiple lines in javascript. It will then look for a " at the end of the first line.

Instead of:

<script>
   document.all.divTest.body.innerHTML = '<table><tr>
     <td>Test</td>
     </tr></table>'
</script>


I need the output of the write (or another function) to be something like:

<script>
   document.all.divTest.body.innerHTML = '<table><tr>\n<td>Test</td>\n</tr></table>'
</script>


Galilee

RE: Problem with the out.write function

Dear Galilee,

Thanks for helping me see the problem. duh!

Anyway here is what you need the string to look like, I don't know how it is being generated so I'm not sure what it will take for you to make it look like this:

"<table><tr>\\n<td>Test</td>\\n</tr></table>"

You need to 'escape' all the backslash characters because they are 'escape' characters <redundant> ;o)

Hope this helps
-pete

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close