Online Rich Text Editor with jQuery: Build a Form

To add formatted text entry to a jQuery form, use a field where users can edit formatted content. jQuery TE is a jQuery plugin that enhances a textarea for editing HTML.

I’ll show how to add jQuery TE to a form and read the HTML its textarea submits.

TL;DR: Add a Rich Text Editor to a jQuery Form

jQuery TE enhances a textarea, so keep the textarea as the form field and initialize the plugin after its assets load.

  • Load jQuery, the plugin stylesheet, and the plugin script in that order.
  • Give the textarea a name so the form can send its value.
  • Read and validate the submitted HTML on the server before saving or displaying it.

What Is a jQuery Rich Text Editor?

jQuery TE, often called jqte, is a jQuery plugin for editing HTML in a form field. WYSIWYG describes an interface that previews formatting on the editing surface.

The official project page links demos, downloads, and documentation, and recommends a current jQuery release. The available project material does not establish a current jqte version, so avoid assuming an archived version is current.

How to Add jQuery TE to a Form Step by Step

A form works when the plugin assets load before initialization and the textarea remains a named control that the submit handler can read.

Step 1: Add the textarea and plugin assets

Begin with a textarea and the matching asset files from the jqte download. Load jQuery first, followed by the plugin script and stylesheet.

<form id="article-form" action="/articles" method="post">
  <label for="article-body">Article body</label>
  <textarea id="article-body" name="body"></textarea>
  <button type="submit">Save draft</button>
</form>

<link rel="stylesheet" href="/assets/jquery-te.css">
<script src="/assets/jquery.min.js"></script>
<script src="/assets/jquery-te.min.js"></script>

The asset paths are placeholders, not a package download command. Use HTTPS for remote assets, check the project’s license and file integrity, and avoid copying an old jQuery URL from the live post. A local copy gives you control over deployment, while a CDN can simplify delivery but adds an external dependency.

The label’s for attribute should match the textarea ID, and the textarea name becomes the key in the submitted form data.

Step 2: Initialize the intended field

Initialize by ID when the page has one editor. A class is better when several intended fields share the same behavior. Give each control a distinct ID and label so the user can tell which field the toolbar changes.

$(function () {
  $('#article-body').jqte();
});

The ready callback waits for the document. The project README also shows jqte() called on a textarea.

Step 3: Read the field when the form submits

Read the textarea’s current value in the submit event and let the browser send the named control with the form.

$('#article-form').on('submit', function (event) {
  const html = $('#article-body').val();

  if (!html || !html.trim()) {
    event.preventDefault();
    return;
  }
});

jQuery’s val() reads a form control’s value, including a textarea. Check the request in your server’s development logs or inspect the form payload in browser developer tools to confirm the body key contains the edit. Do not infer persistence from the toolbar alone.

A regular form submission sends the named field according to the form’s method and encoding. POST places the value in the request body, while GET places it in the URL, so use a body-based method for formatted content. On the server, read the matching body parameter, validate its size and content type, and return a success response only after the save completes.

For an asynchronous save, prevent the default submission only when your handler will send the request, then report success or failure to the user. CodeForGeek’s guide to jQuery on() event handlers explains the event-binding method used here. Keep transport logic separate from editor setup so a failed save does not erase the draft.

Common jQuery TE Form and HTML Issues

Integration faults often come from a missing plugin or a value read from the wrong element.

SymptomLikely causeNext check
jqte is not a functionThe plugin script did not load, or initialization ran firstCheck the script URL, network response, and load order
Saved value is emptyThe textarea lacks a name, or code reads a different fieldInspect the form payload and selector
Formatting appears as tags or breaksThe stored HTML was escaped or normalized at another layerInspect the submitted value before changing rendering
Unexpected markup appears on a pageUntrusted submitted HTML was rendered without a safe allowlistSanitize on the server and encode output for its context

At the server boundary, validate the received HTML and apply a maintained allowlist sanitizer before storage.

When a saved entry is loaded for another edit, place its value in the textarea through the server framework’s HTML-escaping helper for that context. The browser then exposes the field value to the editor, while unsafe characters are not parsed as page markup before the control is built.

When the toolbar permits links, test a normal URL and reject schemes your product does not accept. The sanitizer policy should cover attributes as well as tags.

jQuery TE is an older, narrow plugin choice rather than a guarantee of current maintenance. If its dependencies or accessibility behavior do not fit your project, evaluate a supported editor such as Quill or CKEditor against your requirements before migrating. CodeForGeek’s guide to jQuery GET and POST methods covers request handling when a form needs an AJAX path.

Conclusion

Keep the named textarea as the form’s data path and confirm its submitted field before choosing storage.

The jQuery TE documentation and jQuery val() reference describe the APIs used in this setup.

FAQ

These answers cover the common value and submission questions around a textarea-based editor.

How do I get the HTML from jQuery TE?

Read the named textarea’s current value in the form submit handler with jQuery val(), then confirm the submitted field on the server.

Can I save jQuery TE content to a database?

Yes. Submit the textarea value to your server, validate and sanitize the HTML there, then store it using your application’s persistence layer.

Is content from a rich text editor safe to render?

No. Treat submitted HTML as untrusted input, apply a server-side allowlist sanitizer, and render it according to your output context.

Pankaj Kumar
Pankaj Kumar

Pankaj Kumar is the founder and CEO of CodeForGeek, with more than 14 years in IT. He is an open-source enthusiast who enjoys sharing what he learns through CodeForGeek and YouTube, with a focus on Python, data analytics, machine learning, Angular, Node.js, and Kafka.

Articles: 337