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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:12:27+00:00 2026-05-30T18:12:27+00:00

I’m trying to follow the prof’s example of creating an editable table on double

  • 0

I’m trying to follow the prof’s example of creating an editable table on double clicking an entry in a HTML table. So my data method looks like this:

function formatData(message) {
    var str = "<table border=1>";
    for (var i = 0; i < message.length; i++) {
        str += "<tr>" + "<td class='editable'>" + message[i].id + "</td>" +
                       "<td>" + message[i].name + "</td>" +
                       "<td class='editable'>" + message[i].url + "</td>" +
                       "<td class='editable'>" + message[i].desc + "</td>" + 
                       "<td>" + "<a href='#' onclick='deleteRequest(this); return false' id='" + message[i].id +                                        "'>delete</a>" + "</td>" + 
                       " + "</td>" + "</tr>";
    }
    str += "</table>";
    return str;
}

I bind a function edit() to the tags whose attributes are of class ‘editable.’ Then my edit function does:

function edit(elm) {
  /* check to see if we are already editing */
  if (elm.firstChild.tagName && elm.firstChild.tagName.toUpperCase() == "INPUT")
    return;

  /* save original content */
  var orig = elm.innerHTML;

  /* create edit field */
  var input = document.createElement("input");
  input.type = "text";
  input.value = elm.innerHTML;
  input.size = 20;

  /* convert content to editable */
  elm.innerHTML = '';
  elm.appendChild(input);

  /* position cursor and focus */
  if (input.selectionStart)
    input.selectionStart = input.selectionEnd = 0;
  else
    {
     var range = input.createTextRange();
     range.move("character", 0);
     range.select();
    }
  input.focus();

  /* set save trigger callback */
  input.onblur = function(){save(elm, input,orig);};
}

I’m confused on how I would save the information and pass it to the web server to update. I need the id, url, and desc to update the web server. Since they double click on a table entry, that just gives me the element at that value, but I don’t have the id. Do I change two lines in my formatData to:

"<td class='editable' id='" + message[i].id + "'>" + message[i].url + "</td>" +
"<td class='editable' id='" + message[i].id +"'>" + message[i].desc + "</td>" + 

So that way I can ask the webserver for the url and desc with that id value? That seems like a bad way to do it since now two have the same id, but I’m not sure since I’m relatively new to AJAX, HTML, Javascript. Thanks.

  • 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-30T18:12:28+00:00Added an answer on May 30, 2026 at 6:12 pm

    Eh, I’ll push a bit of help your way.

    Basically, from what I gather you’re binding a function to each td tag with editable. Well, you can determine the id inside that function.

    B/c you can select the parentNode of the current node being edited, and then select the firstChild of that parentNode, so parentNode.firstChild which should be the first td, since remember on each row each of your td‘s will have a single parent tr. Then you select the firstChild of that td node, which is the text node it contains, and then grab its value, the id. So parentNode.firstChild.firstChild.nodeValue

    This might not follow exactly with your code, as you only show parts of it… but this is the gist of the idea. Basically selecting nodes through the DOM and pulling the right one based on the current context.

    I’d suggest playing around with it till you get it.

    Here’s a little bit of sample code for you to think about if you get stuck still. It’s meant to be brief.

    Basically, each middle column is tagged with the test function on the onfocus event (clicking inside the input). So it’s on the input itself, and it pulls the parentNode td, then the next parentNode tr, then the firstChild of tr which is the first td then the firstChild of the first td which is the input on that row, then finally that input‘s value attribute.

    <script>
    function test(elem) {
    
        alert( elem.parentNode.parentNode.firstChild.firstChild.value );
    }
    </script>
    
    <table>
    <tr><td><input value="1"/></td><td><input value="stuff" onfocus="test(this)"/></td><td>other stuff</td></tr>
    <tr><td><input value="2"/></td><td><input value="stuff3" onfocus="test(this)"/></td><td>other stuff</td></tr>
    <tr><td><input value="3"/></td><td><input value="stuff2" onfocus="test(this)"/></td><td>other stuff</td></tr>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
i got an object with contents of html markup in it, for example: string
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to run a str_replace or preg_replace which looks for certain words

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.