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

  • Home
  • SEARCH
  • 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 9111645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:33:21+00:00 2026-06-17T03:33:21+00:00

In the script below, I want to keep the initial value of htmlStrTOCpre static

  • 0

In the script below, I want to keep the initial value of htmlStrTOCpre static so that it does not change. However, once I edit the text area, the undo will no longer paste the original text back into the textarea. I believe its because the htmlStrTOCpre is based on the html() of textarea at the time the undoTOC function is called, and not the initial value on page load.

How can I store that initial value, so that I can always paste it back into the textarea (via the undoTOC function)?

<script>
jQuery(document).ready(function()
    {
        var pageurl = jQuery("#sample-permalink").text();
        var htmlStrTOCpre = jQuery("#cb2_customTOC").html();
        var htmlStrTOC  = '<h3>Table of Contents</h3>\n';
        htmlStrTOC += '<ul>\n';
        htmlStrTOC += '    <li><a href="'+pageurl+'">Introduction&nbsp;</a></li>\n';
        htmlStrTOC += '    <li><a href="'+pageurl+'2/">Introduction&nbsp;</a></li>\n';
        htmlStrTOC += '    <li><a href="'+pageurl+'3/">Conclusion&nbsp;</a></li>\n';
        htmlStrTOC += '</ul>';

        var checkTOC = function()
        {
            jQuery("#cb2_customTOC").html(htmlStrTOC);
        }

        jQuery("#cb-toc-click").bind("click", checkTOC);

        var undoTOC = function()
        {
            jQuery("#cb2_customTOC").html(htmlStrTOCpre);
        }

        jQuery("#cb-toc-undo").bind("click", undoTOC);

</script>

<div id="post_TOC" class="postbox ">
    <h3 class="hndle"><span>Table of Contents</span></h3>
    <div class="inside">
        <style>
        .cb-toc{color:blue;text-decoration:underline;cursor:pointer;}
        </style>
        <div class="inside">
            <textarea name="cb2_customTOC" id="cb2_customTOC">Some initial value</textarea>
            <span class="cb-toc" id="cb-toc-click">Paste TOC</span> | <span class="cb-toc" id="cb-toc-undo">Undo</span></p>
        </div>
    </div>
</div>

<span id="sample-permalink">http://localhost:8888/test/</span>
  • 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-17T03:33:22+00:00Added an answer on June 17, 2026 at 3:33 am

    Here You will find my solution: http://jsfiddle.net/EBqZy/, btw I will corect Your code bellow.

    jQuery(document).ready(function()
    {
        var pageurl = jQuery("#sample-permalink").text();
        var htmlStrTOCpre = jQuery("#cb2_customTOC").text();
    
        var htmlStrTOC  = '<h3>Table of Contents</h3>\n';
        htmlStrTOC += '<ul>\n';
        htmlStrTOC += '    <li><a href="'+pageurl+'">Introduction&nbsp;</a></li>\n';
        htmlStrTOC += '    <li><a href="'+pageurl+'2/">Introduction&nbsp;</a></li>\n';
        htmlStrTOC += '    <li><a href="'+pageurl+'3/">Conclusion&nbsp;</a></li>\n';
        htmlStrTOC += '</ul>';
    
        var checkTOC = function()
        {
            jQuery("#cb2_customTOC").val(htmlStrTOC);
        }
    
        jQuery("#cb-toc-click").bind("click", checkTOC);
    
        var undoTOC = function()
        {
            jQuery("#cb2_customTOC").val(htmlStrTOCpre);
        }
    
        jQuery("#cb-toc-undo").bind("click", undoTOC);
    
    })
    
    
    <div id="post_TOC" class="postbox ">
    <h3 class="hndle"><span>Table of Contents</span></h3>
    <div class="inside">
        <style>
        .cb-toc{color:blue;text-decoration:underline;cursor:pointer;}
        </style>
        <div class="inside">
            <textarea name="cb2_customTOC" id="cb2_customTOC">Default text</textarea>
            <span class="cb-toc" id="cb-toc-click">Paste TOC</span> | <span class="cb-toc" id="cb-toc-undo">Undo</span></p>
        </div>
    </div>
    

    http://localhost:8888/test/

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

Sidebar

Related Questions

I have the below code that does not seem to work at all :(
I have a JSON like what you see below, that I want to keep
I want to get the height and width of an image that does not
I want to use the script below to add pdf files stored as blob
I have a bash script as below, and I want it to read two
I have a NAnt script like below: <target name=Init unless=${target::has-executed('Init')}> What I want is
I want to enable auto update script in flex3. i am using below code
I have the below line in the unix shell script. I want to exclude
The script below works fine if 3 and 3.2 are not links but i
I'm a newbie to PowerShell. What's wrong with my script below? It's not wanting

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.