linebreak on preview

C

chadlupkes

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: " +
document.getElementById('subject').value;
var messagebody = document.getElementById('body').value;
var sendername = document.getElementById('firstname').value + " " +
document.getElementById('lastname').value;
var senderaddress = document.getElementById('address').value;
var sendercity = document.getElementById('city').value;
var senderstate = document.getElementById('state').value;
var senderzip = document.getElementById('zip').value;
var senderphone = document.getElementById('phone').value;
var previewtext = messagesubject + "<br><br>" + messagebody +
"<br><br>" + sendername + "<br>" + senderaddress + "<br>" +
sendercity + ", " + senderstate + " " + senderzip + "<br>" +
senderphone;
document.getElementById('previewdiv').innerHTML = previewtext;
}

The issue seems to be that linebreaks are not included in the
preview. I don't know how to identify where those are and how to get
them to show up correctly.

Can anyone help?

Chad
 
R

RobG

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: " +
document.getElementById('subject').value;
var messagebody = document.getElementById('body').value;

If those elements are in a form, why not use the form's elements
collection and save yourself a lot of typing? I'll presume that
you've supplied names that are the same as the IDs so that non-
scripted or script-disabled browsers will still submit the form:

var f = document.getElementById('formID');
var messagebody = f.elements['body'].value;
...

[...]
var previewtext = messagesubject + "<br><br>" + messagebody +
"<br><br>" + sendername + "<br>" + senderaddress + "<br>" +
sendercity + ", " + senderstate + " " + senderzip + "<br>" +
senderphone;
document.getElementById('previewdiv').innerHTML = previewtext;

}

The issue seems to be that linebreaks are not included in the
preview. I don't know how to identify where those are and how to get
them to show up correctly.

Can anyone help?

Presumably one of them (messagebody?) is a textarea element and you
want to replace line-breaks with BR elements. One of these should
help:

"How to display TextArea value in <Span> innerHTML with <br> in
Netscape"
<URL:
http://groups.google.com.au/group/c...text+area+line+breaks&rnum=3#8c0025149b4f27ae
"Problem with innerText/textContent"
<URL:
http://groups.google.com.au/group/c...text+area+line+breaks&rnum=1#7c50650b0c6dd546
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,787
Messages
2,569,631
Members
45,338
Latest member
41Pearline46

Latest Threads

Top