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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:15:24+00:00 2026-06-18T14:15:24+00:00

This is what I’m trying to do: I have a table, created from Javascript

  • 0

This is what I’m trying to do: I have a table, created from Javascript with user input in each cell. This table is just to confirm that the data entered by the user is correct. If the user sees an error, they click on the cell which needs editing, and it puts a textbox in the table cell with the current cell data. The user will then be able to submit changes or discard the changes if they clicked on the wrong cell. This is currently what I have:

    <table id = "confirm">
      <tr><th>Firstname</th><td id = "txtFirstname" onclick = "update(this.id)">Adan</td></tr>
      <tr><th>Lastname</th><td>Smith</td></tr>
      <tr><th>Username</th><td>ASmith</td></tr>
      <tr><th>Email</th><td>abc@123.com</td></tr>
      <tr><th>Phone</th><td>123-456-7890</td></tr>
    </table>

<script type = "text/javascript">
  function update(id){
    //Get contents off cell clicked
    var content = document.getElementById(id).firstChild.nodeValue;
    //Switch to text input field
    document.getElementById(id).innerHTML = "<input type = 'text' name = 'txtNewInput' id = 'txtNewInput' value = '" + content + "'/>";
  }
</script>

This is what my current code does: When user clicks on the cell, it replaces it with the current text inside a textbox, which is great, but when you try to edit the text, it calls the function over again replacing the text with “null”. Please help me figure this out!

  • 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-18T14:15:26+00:00Added an answer on June 18, 2026 at 2:15 pm

    It is caused by event bubbling. You didn’t want onclick to apply to input, but unfortunately this is not the case. To solve this problem, simply do this (taken from http://jsfiddle.net/DerekL/McJ4s/)

    table td, th{
        border: 1px solid black;
    }
    <table id="confirm">
        <tr>
            <th>Firstname</th>
            <td contentEditable>Adan</td>
        </tr>
        <tr>
            <th>Lastname</th>
            <td>Smith</td>
        </tr>
        <tr>
            <th>Username</th>
            <td>ASmith</td>
        </tr>
        <tr>
            <th>Email</th>
            <td>abc@123.com</td>
        </tr>
        <tr>
            <th>Phone</th>
            <td>123-456-7890</td>
        </tr>
    </table>

    Why do it with JavaScript when simple HTML can do the same thing? ;)


    Internet Explorer:

    There is a strange “bug” in IE that it won’t allow a table cell to be editable (why, Microsoft?) So you have to wrap your content with a <div> (taken from http://jsfiddle.net/DerekL/McJ4s/3/):

    table td,
    th {
      border: 1px solid black;
    }
    <table id="confirm">
      <tr>
        <th>Firstname</th>
        <td>
          <div contenteditable>Adan</div>
        </td>
      </tr>
      <tr>
        <th>Lastname</th>
        <td>Smith</td>
      </tr>
      <tr>
        <th>Username</th>
        <td>ASmith</td>
      </tr>
      <tr>
        <th>Email</th>
        <td>abc@123.com</td>
      </tr>
      <tr>
        <th>Phone</th>
        <td>123-456-7890</td>
      </tr>
    </table>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
This should be another simple fix that is confusing me. I'm pulling data from
This is my code. In spite of the fact that it has confirm, it
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This is the website . I have an strange text display error that it's
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
This is an issue I have been trying to fix for a while. I
This should be a simple one: I have an observableArray object called To in
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.

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.