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 914057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:39:31+00:00 2026-05-15T17:39:31+00:00

I’ve written a rudimentary text editor for my page. Any tag with the .edit

  • 0

I’ve written a rudimentary text editor for my page. Any tag with the .edit class can be clicked by a logged in user and a form appears with the text in the textarea field to be edited in addition to unbinding the ‘click’. Upon submit the function performs a post and updates the database via a ColdFusion component and reloads the page to reflect the changes made. Works great (thanks in no small part to the Stackoverflow community and Ray Camden).

I created a ‘cancel’ function that clears the form field (because it’s reusable) and re-binds teh ‘click’. The trouble is, I see in firebug that if I click some text, cancel, click some other text and then click submit my code performs two posts – one for the cancelled click and one for the real thing.

What do I need to do to kill that first aborted effort?

Here’s the code:

    $(document).ready(function() {

$('#cancelEdit').click(rebinder);
$('.edit').click(texteditor);

function texteditor(){
    var theName = $(this).attr('name'); 
    var textToEdit = $(this).html();
    var theParentID = $(this).closest('div').attr('id');
    var theTag = this.tagName.toLowerCase();
    var theID = theName.split("-")[1];
    var gateway = ("<cfoutput>#URL.page#</cfoutput>");
    var fieldDims = [$(this).css('width'), $(this).css('height')];

    $('#theText').attr('value', textToEdit );
    $('#theText').css('height', fieldDims[1]);
    $('#theText').css('width', fieldDims[0]);
    $('.edit').unbind('click');


    $('#texteditform').submit(function(e){
    //stop the form submission
      e.preventDefault()
        var newText = $('#theText').val();
        //CFC
        $.post("cfc/engine.cfc?method=updateText&returnformat=json", 
            {text:newText, field:theID, gateway_id:gateway},
            function(res) {
                //Handle the result
                if(res.trim() == "true") {
                    $('#theText').attr('value', '');
                    location.reload();
                    //$('.edit').bind('click');
                } else {
                    alert("Didn't Work");
                }
            });
    });

    };

function rebinder(){
    alert('rebinder');
    $('.edit').click(texteditor);
    $('#theText').attr( 'value', '' );
    $('#theText').css('height', '');
    $('#theText').css('width', '');
};


// End of document.ready function //                
});

I just looked at the console and not only does the post happen twice but it posts the text from the second attempt to both post efforts which, unfortunately updates both elements with the .edit class. That’s bad…

  • 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-05-15T17:39:31+00:00Added an answer on May 15, 2026 at 5:39 pm

    You’re binding the submit event on the form multiple times. Move the binding out of the texteditor function or unbind the event before binding again.

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

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a

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.