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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:22:27+00:00 2026-05-22T14:22:27+00:00

I have an HTML5 Canvas. When the user double-clicks in a particular region of

  • 0

I have an HTML5 Canvas. When the user double-clicks in a particular region of that canvas, I want a single-field form to appear at that spot, so that the user can edit some text.

My intended effect is similar to this screenshot from Google Docs. I double-clicked on the shape with the “Hello” text, and the editable text field appeared.

I’ve worked out how to detect the double-click, the mouse location, and the text. But so far I’m using a javascript “prompt(…)” dialog to edit the text, which is not what I want.

enter image description here

I guess I’m looking for something to put in this function to replace prompt:

// let the user edit the text, by showing a popup-field that appears at (x, y)
function editText(x, y, text) {
    return prompt('Text:', text);
}

If it is relevant, I’m using jQuery a little.

  • 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-22T14:22:28+00:00Added an answer on May 22, 2026 at 2:22 pm

    Apprise didn’t seem to do everything you were asking so I wrote this: http://jsfiddle.net/Qj9QR/12/

    CSS

    .prompt { position: absolute; background-color: #E0ECFF; border-radius: 3px; width: 200px; height: 50px; border: 1px solid #99C0FF }
    .prompt textarea { margin: 4px 0 0 4px  }
    .prompt .hint { position: absolute; bottom: 1px; left: 5px; font-size: 9px; color: #444466 }
    

    JS uses jQuery see fiddle

    function prompt(opts){
        this.opts = $.extend({}, this.defaults, opts);
        this.init();
        this.open();
    }
    
    prompt.prototype = {
        defaults: { x: 0, y: 0, text: 'Type Here' },
        init: function(){
            this.create();
            this.bind();
            this.position();
        },
        bind: function(){
            var self = this;
            this.el.click(false).find('textarea').bind('keypress', function(e){
                if(e.which === 13) self.close(e);
            });
            $(document).bind('click.prompt', $.proxy(self.close, self));
        },
        close: function(e){
            if(this.opts.close){
                this.opts.close.apply(this, arguments);
            }
            if(!e.isPropagationStopped()){
                $(document).unbind('click', this.close);
                this.el.remove();
            }
        },
        create: function(){
            this.el = $('<div class="prompt" />')
                .append('<textarea></textarea>')
                    .find('textarea').val(this.opts.text)
                    .end()
                .append('<span class="hint">Hint: use Shift-Enter for multiple lines</span>');
        },
        position: function(){
            this.el.css({top: this.opts.y, left: this.opts.x });
        },
        open: function(){
            this.el.appendTo('body');
            this.el.show('fast')
                .find('textarea').focus().select();  
        } 
    };
    // IN USE: when you click an LI update some html
    $('li').click(function(){
        var li = $(this),
            pos = li.position();
        new prompt({
            text: li.html(), 
            x: pos.left, 
            y: pos.top + 17, 
            close: function(e){
                var newText = $(e.target).val();
                newText && li.html(newText);
            } 
        });
        return false;
    });
    

    Updated with position and updating element values

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

Sidebar

Related Questions

I have external html5 canvas that you can paint on some lines using your
Is there a putpixel functionality in html5. I have a canvas and want to
I have a doodle application that saves an html5 canvas to an image in
I have a drawing application using html5 canvas. When the user is drawing and
I have HTML5 canvas where the user has created an image. This is for
I have an HTML5 Canvas on my page along with two text input fields.
I havent had much exposure to the Canvas element in HTML5. I have done
I have a HTML5 canvas on which I have drawn several shapes. What I
I'm writing a web app that uses an HTML5 canvas and testing on a
HTML5 introduces some nice new elements, <canvas> , <audio> , and <video> , that

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.