how to capture textarea content format and embed it in html style email?
Code:
<textarea id="mailContent" title="Email Content" maxLength="1500" name="mailContent" cols="77" rows="16"></textarea>
Hi, i have the code above to let a user type in message and then the user will click a send button to send content in the textarea as a html email(this is my intention).
however, during my test, i find that all content in the textarea are in plain text, ie, it dont have paragraph or empty line as in what i gave type in the textarea.
can someone help, teach me how to capture the origainal format of text area and send it as it is in the email.
:rolleyes:
Re: how to capture textarea content format and embed it in html style email?
Do you mean you want to capture rich text rather than plain text that the textarea only uses.
You'll need a third party control such as http://www.freetextbox.com/ - this is a control for ASP.NET sorry but I'm not aware of one for ASP. I expect someone else here will though!
DJ
Re: how to capture textarea content format and embed it in html style email?
You can use an IFRAME control to allow for formatting.
Re: how to capture textarea content format and embed it in html style email?
Quick example of what I've done:
Code:
<td vAlign="top" align="left" width="100%" colSpan="4"><table cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr>
<td width="2%"></td>
<td width="96%" colSpan="3"><iframe class="csBodyText" id="idContent" width="100%" onload="populateIFrame(); document.forms.frmResume.txtFullName.focus();"
height="500"></iframe>
</td>
<td width="2%"><input id="txtResumeHTML" type="hidden" runat="server"></td>
</tr>
<tr>
</tr>
</table>
</td>
Then some javascript:
PHP Code:
<script language="javascript" type="text/javascript">
function populateIFrame(){
setMode(1);
idContent.document.body.innerHTML = document.frmResume.txtResumeHTML.value;
setMode(0);
}
function document.onreadystatechange()
{
idContent.document.designMode="On";
}
function cleanHtml() {
var fonts = idContent.document.body.all.tags("FONT");
var curr;
for (var i = fonts.length - 1; i >= 0; i--) {
curr = fonts[i];
if (curr.style.backgroundColor == "#ffffff") curr.outerHTML = curr.innerHTML;
}
}
function setMode(newMode) {
bTextMode = newMode;
var cont;
if (bTextMode) {
cleanHtml();
cleanHtml();
cont=idContent.document.body.innerHTML;
idContent.document.body.innerText=cont;
} else {
cont=idContent.document.body.innerText;
idContent.document.body.innerHTML=cont;
}
idContent.focus();
}
// function HTMLEncode(t) {
// var t = t.toString().replace(/&/g, "&").replace(/"/g, """);
// return(t.replace(/</g, "<").replace(/>/g, ">"));
//}
function HTMLEncode(t) {
var str = new String(t);
str = str.replace(/&/g, "&");
str = str.replace(/</g, "<");
str = str.replace(/>/g, ">");
str = str.replace(/"/g, """);
return str;
}
//"
function savedocument() {
setMode(1); //switch doc to html mode for save
document.frmResume.txtResumeHTML.value=HTMLEncode(idContent.document.body.innerText);
setMode(0); //switch doc back to text mode
}
</script>
In the button click event, I take the value in the iframe, save it to the hidden field and work with it in code.
HTH
Re: how to capture textarea content format and embed it in html style email?