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!

*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.

Jobs

How to format text in a Textarea?

How to format text in a Textarea?

(OP)
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

RE: How to format text in a Textarea?

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.

RE: How to format text in a Textarea?

(OP)
The pasting part is done manually by the user.
Maybe I should have put this post in the HTML/CSS forum.

RE: How to format text in a Textarea?

Nothing at all to do with 'pasting', it is what collects the form when submitted and then creates and sends the email

Quote:

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.

RE: How to format text in a Textarea?

(OP)
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?

RE: How to format text in a Textarea?

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

RE: How to format text in a Textarea?

(OP)

Quote (vacunita)

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

RE: How to format text in a Textarea?

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

RE: How to format text in a Textarea?

Why depend on the user's email program/service? Why don't you just mail it yourself?

RE: How to format text in a Textarea?

(OP)

Quote (vacunita)

What are you pasting th3e copied text into?
Into an email message.

Quote (spamjim)

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).

RE: How to format text in a Textarea?

Quote (javier)

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

RE: How to format text in a Textarea?

(OP)
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.

RE: How to format text in a Textarea?

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.

https://stackoverflow.com/questions/4782068/can-i-...

RE: How to format text in a Textarea?

(OP)

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 ?

RE: How to format text in a Textarea?

It appears that Chrome can be configured by either a manual setting or an optionally installed extension. If your team is small, it may not be a challenge to configure this.

https://www.google.com/search?q=mailto+link+gmail+...

Then, instead of using JS to write data to a textarea to copy, you just write it to a mailto link.

RE: How to format text in a Textarea?

(OP)
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",
"https://mail.google.com/mail/?extsrc=mailto&ur...",
"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?

RE: How to format text in a Textarea?

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.

RE: How to format text in a Textarea?

(OP)
Fare enough!
Thanks for your help guys :)

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!

Resources

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