Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to format text in a Textarea? 1

Status
Not open for further replies.

javierdlm001

Technical User
Jun 28, 2008
264
CA
I am using this widget to copy a list to the operating system's clipboard, to then paste it in an email message.
The problem is, I the resulting list is not a list as much as it is a block of text.
How can I better control the results?

Thanks guys
 
Not with javascript, because javascript cannot create and format emails. It will have to be done in whatever server side code is being used to collect the form data.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
The pasting part is done manually by the user.
Maybe I should have put this post in the HTML/CSS forum.
 
Nothing at all to do with 'pasting', it is what collects the form when submitted and then creates and sends the email

Maybe I should have put this post in the HTML/CSS forum

Nope, because HTML cannot do what you want either. UNLESS all the people filling in the form are fluent in HTML.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Just to be sure we're on the same page, did you have a look at the Copy to clipboard widget I am talking about?
 
The Copy to clipboard will copy whatever is in the textbox, its up to the receiver to respect the format.

If pasted in an email client, the email client would need to understand what the format you pasted was. There's not much you can do to the copied text, since its just a string.

The link above opens a Stack Overflow page with several possible answers. Which one are you using exactly? How is the textarea from which its being copied formatted? Why A textarea? Are you expecting the user to type anything in the text area before copying?

What happens if you try to paste into a different application instead of the email message being composed?



----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
vacunita said:
Why A textarea?
Actually, it doesn't have to be a textarea. It could just be text to be clicked, or a button. The objective is to have a list of items copied to the clipboard, then pasted to an email message. Once there the list must remain formatted as a list.

I hopes this helps
 
This code from your link works for me, and retains formatting in the 2 email clients I tested.

Code:
function CopyString(elID){
    var StringToCopyElement = document.getElementById(elID);
    StringToCopyElement.select();

    if(document.execCommand('copy')){
        StringToCopyElement.blur();     
    }else{
        CopyStringMobile(elID);
    }
}

function CopyStringMobile(elID){
    document.getElementById(elID).selectionStart = 0;
    document.getElementById(elID).selectionEnd = 999;
    document.execCommand('copy');

    if (window.getSelection) {
      if (window.getSelection().empty) {  // Chrome
        window.getSelection().empty();
      } else if (window.getSelection().removeAllRanges) {  // Firefox
        window.getSelection().removeAllRanges();
      }
    } else if (document.selection) {  // IE?
      document.selection.empty();
    }
}

What are you pasting th3e copied text into?



----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
Why depend on the user's email program/service? Why don't you just mail it yourself?
 
vacunita said:
What are you pasting th3e copied text into?
Into an email message.

spamjim said:
Why don't you just mail it yourself?
Thanks for joining spamjim :)
Simply because 1. At least at the moment, I don't have the technical skills needed. And 2. because I am in a secured network at work (just a Call Center).
 
javier said:
Into an email message.
I meant what application?

I tested in Thunderbird, and Windows Mail App, and both retained the formatting from the text area.

What does the text you are copying look like exactly? Is it an HTML list (<ol><li>...</li>...</ol>)? Or just a regular text (1.item1, 2.item2...)?



----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
Oh, I see. It's Gmail, using Chrome in Windows 7.
The text looks like the latter: just regular text, about 9 rows, 1 column.
When I past it in Gmail the lines of text change their original row positions, as a result many will be starting in the previous row above, and continuing in the next row below. Unfortunately this makes you work quite a bit just to re-format it, which defeats the whole purpose of "simplifying" that task.
 
I think I understand now but correct me if I'm wrong...you're creating an in-house tool for fellow employees with Chrome to send with their Gmail accounts. While much of this discussion is dangerous for the general public with multiple browsers and email programs to support, you're better off if you can limit this to a single known environment.

As an alternative to copy/paste, does your browser support direct mailto links (I believe the user needs to be "signed in" to Chrome for this to work)? You could pack the text and formatting into the body attribute so that a new email is composed with a click of a button on your web page.

 

I think you got it spanking!
"limit this to a single known environment"
Yes, that's exactly the situation. We're a small group of about 14.

I tested the mailto link, but is not working. Hopefully is just a matter of changing a setting in Chrome.
So, what do you have in mind? Is it with some JS ?
 
Right. That's what I found. I'll try your link soon.
I found this JS script that would allow Chrome to process mailto links.

Ctrl Shft j

navigator.registerProtocolHandler("mailto",
" "Gmail);"

But unfortunately it didn't for me.
I also read somewhere that there's a setting under "Handlers" to change for this to work. Except although I did find a section under Advance Settings called Handlers, there was nothing specific to handling "mailto links".
Maybe the above are due to the fact that Google is providing this Gmail to our company as a "business solution" so it might be more restricted than the standard one.

I'm thinking that nothing will be done before speaking to our IT department.

Any ideas?
 
Anyone developing any IT solution should certainly be having a dialog with the IT department. A company's IT department will best understand the infrastructure and roadmap. You don't want to develop something for Chrome/Gmail to find out IT is switching to another browser and service in a month. Conversations with IT may also be useful to identify any possible security concerns.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top