Remove html tags when pasting to Textarea

I am using html editor so that when people enter text into the textarea field, they can format the text. But the problem is I don't want to allow people to cut and paste from MS Word to the textarea field with all the preformat text. Is there any way so that when people paste the text from MS Word to the textarea field, all the html tags will be removed automatically? Thanks for help
CochiseCountyAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
b0lsc0ttConnect With a Mentor IT ManagerCommented:
CochiseCounty,

Thanks for the info on the code.  I will try to look at it and see if I can find a solution that can use what I provided and go in the code.  I am afraid I probably won't have time to do that though.  It seems like it would be a major modification or at least would take a lot of time since I would have to learn how the script works.  If you have a link to some info you use to implement the code or a detailed explanation of it then post it.  That could make a difference.

Did you try just doing it like I suggested above?  I don't know if that would work but I am curious if you tried it want what was the result.

If I can't help and other experts don't join in then post a message in a day or two.  I will try to contact some other experts to see if they can/will help.  This is quite a bit to ask but maybe simpler than I see for someone who already knows the script.

Let me know if you have a question about any of this.

bol
0
 
b0lsc0ttIT ManagerCommented:
Since the "source" is actually in the Clipboard when it is pasted then there is no easy way to tell it came from MS Word or not.  If you really had to do this then you would have to look at the html for tags used by and unique to MS Word.  If there are specific things you are trying to keep out then these would be good to search for.  Of course since MS Word can even create 2 versions of html code then this could be harder to detect if you want to catch both.

Let me know how this helps.  If you need any help with code then does this need to be done in the browser (i.e. with Javascript) or can it be done with server script?  Let me know if you have a question about anything.

bol
0
 
CochiseCountyAuthor Commented:
I prefer to do it with Javascripts. Like when people paste the the textarea, all the html tags are removed automatically.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
mrichmonCommented:
Are you looking to remove all html tags only or all formatting - i.e. end up with just plain text pasted.
0
 
CochiseCountyAuthor Commented:
yes, end up with just plain text pasted
0
 
GoofyDawgCommented:
Unfortunately, there's not an easy way of doing that before they paste. IE has an onbeforepaste event, but it's a bit quirky to use. There's no such thing in other browsers.
0
 
b0lsc0ttIT ManagerCommented:
Maybe I misunderstood.  You don't want an html at all?  If that is the case then this isn't hard.  Of course you could also just accept the html tags (if provided) an encode the to html entities.  Javascript or your server language could do this.  If you really want to strip all tags then don't depend on Javascript.  It can be disabled, etc and so your server script should really do this if you want to remove all html tags or make them "safe."

I thought you just wanted to remove the ugly (my word) html that MS Word makes, even using the filtered option.  Please clarify and let me know what you think of the above if you do want all gone.

bol
0
 
CochiseCountyAuthor Commented:
Ok, here's my situation. People in my office have to submit weekly report, the form they are using right now is an asp form, with a textarea field. When they paste into this field the text from a Word document, it removes all the html tags.
What I want is giving them the ability to format the text that they paste into the textarea field, and only alow, Bold, Italic, Underline, Bullets. So I replaced the textarea field with the htmleditor page, but the problem is when they paste into this field the text from a Word document, it keeps all the html tags. So I am trying to find a way sothat when they paste into the htmleditor field, all the html tags are removed.
Hope this help. And thanks for any help.
0
 
b0lsc0ttIT ManagerCommented:
To remove all html from the contents of the textarea you would use ...

<textarea [your other tags] onblur="this.value = this.value.replace(/<\/?[a-z][a-z0-9]*[^<>]*>/ig, "");">

The Javascript is based on an expression I got and have use from JGSoft and their RegexBuddy program.  I don't know how well that will work in the htmlarea you are using.  You can try it as is but I don't know if it will remove some of the formatting you added with the htmlarea.  If there is a problem then let us know exactly what you use for the html textarea and provide a link to its website.

Remember, this won't try to see if it is MS Word html.  It will remove all html tags from the contents of the area.  Let me know if you have a question or need more info.

bol
0
 
CochiseCountyAuthor Commented:
OK, here is the js file that I am using for my htmlarea (it's from a web site, not mine). If I want to add something like Onpaste=this.value.replace(/<\/?[a-z][a-z0-9]*[^<>]*>/ig, ""), where should I add. Thanks for help
//
// htmlArea v2.03 - Copyright (c) 2002 interactivetools.com, inc.
// This copyright notice MUST stay intact for use (see license.txt).
//
// A free WYSIWYG editor replacement for <textarea> fields.
// For full source code and docs, visit http://www.interactivetools.com/
//

** full code removed by b0lsc0tt **
0
 
b0lsc0ttIT ManagerCommented:
I'm glad I could help.  Thanks for the grade, the points and the fun question.

bol
0
All Courses

From novice to tech pro — start learning today.