Using Tinymce 4.1.9 with raw ajax instead of JQuery: A step-by-step guide

I am currently working with Tinymice 4.1.9 for textarea validation in a raw ajax environment as I have limited knowledge of jquery. The issue I'm facing is that when Tinymce 4.1.9 is added to the textarea, upon validation, I receive an empty string unless validated twice.

Below is the snippet of my raw ajax code used for validation:

<script  language="javascript">

   function identification(identification_1,identification_2)
    {
      var OAjax;



       document.getElementById('image_loading_identification').style.display='';

      if (window.XMLHttpRequest) OAjax = new XMLHttpRequest();
      else if (window.ActiveXObject) OAjax = new ActiveXObject('Microsoft.XMLHTTP');
      OAjax.open('POST',"identification.php",true);
      OAjax.onreadystatechange = function()
      {
          if (OAjax.readyState == 4 && OAjax.status==200)
          {

          document.getElementById('image_loading_identification').style.display='none';


              if (document.getElementById)
              {   

                 document.getElementById("identification").innerHTML=OAjax.responseText;






              }     
          }
      }

      OAjax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
      OAjax.send('identification_1='+ encodeURIComponent (identification_1)+'&identification_2='+ encodeURIComponent (identification_2)); 

    }

</script>

My Implementation of Tinymce 4.1.9:

<script type="text/javascript" src="js/jquery/jquery-2.1.1.min.js"></script>

<script src="js/tinymce_4_1_9_jquery/tinymce/js/tinymce/tinymce.min.js" type="text/javascript"></script>
<script src="js/tinymce_4_1_9_jquery/tinymce/js/tinymce/jquery.tinymce.min.js" type="text/javascript"></script>

<script type="text/javascript">

$(function() {
   $('textarea.tinymce').tinymce({
    theme: "modern",
    plugins: [
        "advlist autolink lists link image charmap print preview anchor",
        "searchreplace visualblocks code fullscreen",
        "insertdatetime media table contextmenu paste"
    ],
    toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
   });
});

</script>

The HTML Form Structure:

<form  method="post" name="nomduformulaire_identification" id="nomduformulaire_identification" onsubmit="identification(this.identification_1.value,this.identification_2.value);return false" action="">


<div class="form-group"> 
                        <input name="identification_1" type="text" id="identification_1" class="form-control" placeholder="Name"  autofocus required/>
                    </div>

                    <div class="form-group">


<textarea id="identification_2" name="identification_2" class="tinymce"  style="width:100%"></textarea>

                    </div>    


</form> 

In this scenario, I found that submitting the form twice was necessary for receiving any input from the textarea field "identification_2."

Is there a way to integrate Tinymce 4.1.9 into raw ajax setup without utilizing jQuery and ensure information retrieval from the identification_2 field?

Answer №1

In order to retrieve the content from a textarea, it is advised to perform the following steps:

if (typeof(tinymce) !== 'undefined')
{
    tinymce.save();
    tinymce.clear('textarea');
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

There seems to be an issue with FastAPI not sending back cookies to the React

Why isn't FastAPI sending the cookie to my React frontend app? Take a look at my code snippet: @router.post("/login") def user_login(response: Response, username :str = Form(), password :str = Form(), db: Session = Depends(get_db)): use ...

Validation error occurs in the jQuery form

I've been working on creating a basic form with validation, but for some reason the validation isn't working as expected. I've checked all my tags to make sure they match up, but something seems off with the closing tags at the end of the fo ...

including a code snippet within a dropdown menu or embedding it in a clickable button

Hey there, my name is Wouter Sanders and I am currently learning to code! I recently finished creating a RAL color picker for a project I'm working on. The only issue I've run into is trying to embed the code in a menu or button so that it doesn ...

Tips for implementing next-iron-session with personalized api route middleware in NextJS?

Currently, I am working on implementing session storage with next-iron-session and using Firebase for authentication. Every API route requires both the auth middleware and next-iron-session. This is my first time using NextJS and I have tried several appro ...

Access AJAX Submitted Data on a Classic ASP Page

My current task involves dynamically generating a URL based on a clicked link, extracting variables from the URL, and using them to make an AJAX post request to a classic ASP page. The goal is to insert these values into an SQL database. This process is tr ...

"Sorry, the getJSON function did not return any

I have attempted to execute a simple getJSON(), but it seems like I am not receiving any output. Shown below is my HTML/js: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Management ...

Using linear-gradient() in the border-image property does not actually generate a border

I am attempting to add a linear gradient border around a dynamically created div using JavaScript. However, I am not seeing the border show up as expected and it is not displaying in black. Check out my code snippet below: const devlogList = document.cre ...

Encountering repeated requests (duplicating calls) for each API request while using AngularJS with a JWT authentication token

I'm experiencing a problem with AngularJS(2/4) while attempting to make API calls. The issue arises when each API request contains a JWT Auth Token header, resulting in duplicate API calls. The first request returns no response (despite receiving a 20 ...

Combining the redux toolkit function createAsyncThunk with Angular's HttpClient by leveraging the ApiService

Currently, I am working on incorporating @reduxjs/toolkit into an Angular project. Is there a way to pass an Angular service as a parameter to the callback of createAsyncThunk instead of utilizing fetch directly? I referenced the documentation for an exa ...

Utilize JavaScript to reference any numerical value

I am attempting to create a button that refreshes the page, but only functions on the root / page and any page starting with /page/* (where * can be any number). Below is the code I have written: $('.refresh a').click(function() { var pathNa ...

Universal Navigation Search Component for Vue Router

Just starting out with Vue and frontend development. I'm attempting to create a universal navigation bar in Vue Router using bootstrap vue, complete with a search bar feature. However, because I have placed my navigation bar in App.vue, I am encount ...

The scenario in which a Handlebars if statement transitions to an else statement despite the if statement being true

Issue with if else block in handlebars for messaging feature on social media app. Despite passing empty array of messages from controller, always hitting the else statement. Tried various combinations but still not working. What's the problem? {{#if m ...

Saving the data retrieved from a fetch request at a specified URL into a variable in JavaScript

I'm having some trouble loading data from a URL into a variable using .ready(). When I try to display the value in an alert box, it shows up as undefined. Can anyone offer some guidance on how to fix this? const fetchMasterProd = () => { ...

Angular: Implementing a Dark and Light Mode Toggle with Bootstrap 4

Looking for suggestions on the most effective way to incorporate dark mode and light mode into my bootstrap 4 (scss) angular application. Since the Angular cli compiles scss files, I'm not keen on the traditional method of using separate css files for ...

query the database to retrieve information from a dropdown menu that shows connected services using the CodeIgniter framework

I am currently utilizing both Codeigniter and bootstrap in my project. Within my project, I have two select options named "service" and "sub-service". The values for these options are stored within an array. Here is a visual representation of the options: ...

"Exploring the process of looping through a JSON object following an asynchronous retrieval of JSON data using

I am facing an issue while trying to iterate through a JSON object in jQuery after fetching it asynchronously. I have a function called 'listFiles' that uses async to successfully retrieve a file list from a directory (dir) by calling an API endp ...

Using JQuery's $.post function can be unreliable at times

Looking for help with a function that's giving me trouble: function Login() { var username = document.getElementById('username').value; var password = document.getElementById('password').value; $.post("Login.php", { ...

The absence of $_POST results in the values being stored in $GLOBAL instead

Ever since I reinstalled my OS, I've been encountering a peculiar $_POST issue. When I returned to one of my side projects, I realized that all my POST requests were not functioning properly, despite having worked before. I've observed that all ...

Customizing the appearance of Jquery UI Accordion Headers

Trying to integrate the JQuery UI accordion into my JQuery UI modal dialog has been causing some alignment issues. Despite following code examples found online, such as http://jsfiddle.net/eKb8J/, I suspect that the problem lies in CSS styling. My setup i ...

Tips for displaying the content of a personalized navigation tab using jQuery

I successfully created custom tabs using JQuery. Here is the code for my custom tabs: <div class="row"> <div class="col-4 master-advanced-left-tab master-advanced-left-tab-active"> <p>Item 1</p> </div> < ...