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

linebreak on preview

P: n/a
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

Feb 19 '07 #1
Share this Question
Share on Google+
1 Reply

P: n/a
On Feb 19, 11:59 am, "chadlupkes" <chadlup...@gmail.comwrote:
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 <SpaninnerHTML with <brin
Netscape"
<URL:
http://groups.google.com.au/group/co...0025149b4f27ae
>
"Problem with innerText/textContent"
<URL:
http://groups.google.com.au/group/co...50650b0c6dd546
>

--
Rob

Feb 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.