Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8252869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:40:54+00:00 2026-06-08T00:40:54+00:00

Adding HTML/any tags to either side of selection – Javascript The problem: After creating

  • 0

Adding HTML/any tags to either side of selection – Javascript

The problem:

After creating a textarea box in my PHP/html file I wished to add a little more functionality and decided to make an textarea that can use formatting, for example

<textarea>
This is text that was inserted. <b>this text was selected and applied a style
via a button<b>
</textarea>

It doesn’t matter what the tags are, (could be bubbles for all that I care due to the fact the PHP script, on receiving the $_POST data will automatically apply the correct tags with the tag as the style ID. Not relevant)

The Question/s

  • How can I create this feature using javascript?
  • Are there any links that may help?
  • And can, if there is information, can you explain it?

EDIT: Other close example but not quite is stackoverflow’s editor and note that I do not wish to use 3rd party scripts, this is a learning process for me.
The tags that are inserted in the text are saved to a database and then when the page is requested the PHP replaces the tags with the style ID. If there is a work around not involving 3rd party scripts please suggest

And for the anti-research skeptics on a google search, little was found that made sense and there was Previous Research on SOF:
– https://stackoverflow.com/questions/8752123/how-to-make-an-online-html-editor
– Adding tags to selection

Thanks in Advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:40:56+00:00Added an answer on June 8, 2026 at 12:40 am

    <textarea> elements cannot contain special markup, only values. You can’t apply any styling in a textarea.

    What you’ll need to do is fake everything that a text box would normally do, including drawing a cursor. This is a lot of work, as hackattack said.

    You can do a lot if you grab jQuery and start poking around. Toss a <div> tag out there with an ID for ease and start hacking away.

    I’ve never made one personally, but there is a lot to it. HTML5’s contentEditable can maybe get you a good chunk of the way there: http://html5demos.com/contenteditable/

    If you want to pass this data back to the server, you’ll need to grab the innerHTML of the container and slap that into a hidden input upon submission of your form.

    Here’s other some things you can check out if you’re just messing around:

    • tabindex HTML attribute, to get focus in your box from tabbing
    • jQuery.focus() http://api.jquery.com/focus/, to determine when someone clicks in your box
    • cursor: text in CSS for looks http://wap.w3schools.com/cssref/pr_class_cursor.asp
    • jQuery.keypress() http://api.jquery.com/keypress/, or similar for grabbing keystrokes

    Edit: I think I completely misunderstood

    If you’re not looking for a rich text editor, and just want some helper buttons for code, maybe selectionStart and selectionEnd is what you’re after. I don’t know what the browser support is, but it’s working in Chrome:
    http://jsfiddle.net/5yXsd/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to add namespace xmlns=http://www.w3.org/1999/xhtml to all html tags either using
Is there any way to prevent the Text/HTML Module in DNN from adding tags
I'm currently writing a function for parsing some HTML and adding tags where necessary.
My friend and I are doing something advance on html table tags on php.
Trying to see if there are any negatives to adding HTML comments to my
As the question states, is there any point adding Dublin Core meta-tags to your
I'm adding HTML controls dynamically using java script. For instance, I have one button
i have animated div in html. it is adding 1px to div in every
//html structure <div id='outer'> <div id='inner'> </div> </div> I am adding some data to
this is copied from http://www.zenspider.com/ZSS/Products/RubyInline/Readme.html , the home of rubyinline, adding/moding as indicated in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.