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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:24:39+00:00 2026-05-21T23:24:39+00:00

I created a table with five columns dynamically. Two (the second and third column)

  • 0

I created a table with five columns dynamically. Two (the second and third column) of the five columns should be editable on the fly. Each time when user click on one the editable table cell, JavaScript should catch the user input and send the data to the server in json format. I have problem catch the user input and send to the server. Please help. This is my sample code –

<!DOCTYPE html>
<html>
<head>
  <title>Editable table</title> 
    <style type="text/css" title="currentStyle">        
        @import "css/table.css"; 
    </style>
    <script type="text/javascript" language="javascript" src="js/jquery.js"></script>   

</head>
<body id="dt_example">
    <div id="container">
        <div class="full_width big">
                Data table<br />                
        </div>

    <div class="editab">
        <table border="1">
            <thead>
                <tr>
                    <th>Contract Number</th>
                    <th>Current Status</th>                     
                    <th>Sale Balance Amount</th>
                    <th>Interest Rate</th>
                    <th>Discount</th>
                </tr>
            </thead>
            <tbody>
                <tr>                
                    <td>00123</td>
                    <td onClick="editTableCell(this)">A30</td>
                    <td onClick="editTableCell(this)">$1,500.00</td>
                    <td>3.99 %</td>
                    <td>140</td>
                </tr>
                <tr>                
                    <td>00234</td>
                    <td onClick="editTableCell(this)">B20</td>
                    <td onClick="editTableCell(this)">$2,500.00</td>
                    <td>3.99 %</td>
                    <td>160</td>
                </tr>
                <tr>                
                    <td>00345</td>
                    <td onClick="editTableCell(this)">C40</td>
                    <td onClick="editTableCell(this)">$3,500.00</td>
                    <td>3.99 %</td>
                    <td>180</td>
                </tr>
                <tr>                
                    <td>00456</td>
                    <td onClick="editTableCell(this)">A20</td>
                    <td onClick="editTableCell(this)">$4,500.00</td>
                    <td>3.99 %</td>
                    <td>200</td>
                </tr>
                <tr>                
                    <td>00567</td>
                    <td onClick="editTableCell(this)">B30</td>
                    <td onClick="editTableCell(this)">$5,500.00</td>
                    <td>3.99 %</td>
                    <td>225</td>
                </tr>
                <tr>                
                    <td>00678</td>
                    <td onClick="editTableCell(this)">C10</td>
                    <td onClick="editTableCell(this)">$6,500.00</td>
                    <td>3.99 %</td>
                    <td>250</td>
                </tr>
                <tr>                
                    <td>00789</td>
                    <td onClick="editTableCell(this)">A30</td>
                    <td onClick="editTableCell(this)">$7,500.00</td>
                    <td>3.99 %</td>
                    <td>300</td>
                </tr>                   
            </tbody>
        </table>
    </div>

</div>
<script type="text/javascript">
    var SelectState = false;
    var SelectedElement = null;
    var TextInput = null;
    var CellText = null;
    var txt     = "test";
    var idcount  = 0;

    function editTableCell( e ){

      if ( SelectState == false ){

        SelectedElement = e;
        CellText = e.innerHTML;     
        e.innerHTML = "";

        var objInput = document.createElement("input");
        objInput.type = 'text';
        objInput.value = CellText;
        objInput.id = "txt" + idcount++;
        objInput.onkeypress = editTextBox;
        objInput.size = 15;

        TextInput = objInput;
        e.appendChild(objInput);

        SelectState = true;

      } else if (e != SelectedElement) {
        SelectedElement.innerHTML = CellText;
        SelectState = false;
      }
    }

    function editTextBox( e ){

      if (navigator.appName == "Microsoft Internet Explorer"){
        e = window.event;
        key = e.keyCode;
      }

      else if (navigator.appName == "Netscape"){
        key = e.which;
      }

      if ( key == 13 ){
        SelectedElement.innerHTML = TextInput.value;
        SelectState = false;
      }

      else if ( key == 27 ){
        SelectedElement.innerHTML = CellText;
        SelectState = false;
      }
    }   

/*      var attrName  = "":
    var attrValue = "";
    if ($('#test1')
    {
        attrName=  "editField01";
        attrValue = $(#test1).val();
    }
    if ($('#test2')
    {
        attrName=  "editField02";
        attrValue = $(#test2).val();
    }

    if ($('#test3')
    {
        attrName=  "editField03";
        attrValue = $(#test3).val();
    }

     var values = '{"' + attrName + '":' + attrValue + '}';
      $.ajax({
        url: serverUrl + "/abc/contract/" + poolId,
        async: false,
        type: "PUT",
        data: JSON.stringify(values),
        dataType: 'json',
        processData: false,
        contentType: 'application/json',
        success: showResponse(json) {
          // TODO: What info is returned in the data structure?
          showResponse;
        },
        error: function(err) {
          alert("Failed to update the attribute");
          htmlErrorDialog(err.responseText);
        }
      });*/

    function showResponse(json)  { 
      if(json.success){
        // handle successful response here
        alert("user input from column sent successfully!");
      } else {
        // handle unsuccessful response here
        alert("user input fail to send. Please try again");
      }
    } 
    </script>
</body>
</html>
  • 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-21T23:24:39+00:00Added an answer on May 21, 2026 at 11:24 pm

    You’re not actually passing the json data to showResponse:

        success: showResponse(json) {
          // TODO: What info is returned in the data structure?
          showResponse;
        },
    

    Pass it along as so, and make sure that json is an actual object and that you don’t need to parse it first:

        success: function(json) {
          // check that json is an actual object via an alert
          // alert(json);
          showResponse(json);
        },
    

    EDIT: Okay after a lot of working around, I have a simple test case for making the fields editable. Please note it uses jquery, and comments are inline:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"  "http://www.w3.org/TR/html4/strict.dtd">
    
    <html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Test</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
        <!-- Date: 2011-05-10 -->
    </head>
    <body>
        <form>
        <table border="1">
            <thead>
                <tr>
                    <th>Contract Number</th>
                    <th>Current Status</th>                     
                    <th>Sale Balance Amount</th>
                    <th>Interest Rate</th>
                    <th>Discount</th>
                </tr>
            </thead>
            <tbody>
                <tr>         
                    <!-- The "identifier" class makes it so we have an id
                        to pass to our ajax script so we know what to change -->       
                    <td class="identifier">00123</td>
                    <td class="editable">A30</td>
                    <td class="editable">$1,500.00</td>
                    <td>3.99 %</td>
                    <td>140</td>
                </tr>                   
            </tbody>
        </table>
        </form>     
        <script type="text/javascript">
            // bind our event handler to all td elements with class editable
            $('td.editable').bind('click', function() {
                // Only create an editable input if one doesn't exist
                if(!$(this).has('input').length) {
                    // Get the text from the cell containing the value
                    var value = $(this).html();
                    // Create a new input element with the value of the cell text
                    var input = $('<input/>', {
                        'type':'text',
                        'value':value,
                        // Give it an onchange handler so when the data is changed
                        // It will do the ajax call
                        change: function() {
                            var new_value = $(this).val();
                            // This finds the sibling td element with class identifier so we have
                            // an id to pass to the ajax call
                            var cell = $(this).parent();
                            // Get the position of the td cell...
                            var cell_index = $(this).parent().parent().children().index(cell);
                            // .. to find its corresponding header
                            var identifier = $('thead th:eq('+cell_index+')').html();
                            //ajax post with id and new value
                            $(this).replaceWith(new_value);
                        }
                    });
                    // Empty out the cell contents...
                    $(this).empty();
                    // ... and replace it with the input field that has the value populated
                    $(this).append(input);
                }
            });
        </script>
    </body>
    

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

Sidebar

Related Questions

I have created a table in Visual Studio. That table has two columns. First
I have a table with five columns. The two columns, together, make up the
I have a dynamically created table which in the last <td> there is a
I have a simple mysql table with five columns: id: auto_increment (primary) id_symbol: INT(4)
I have a table with data : id one two three four five six
I have a table which is dynamically created , there is a checkbox in
So I have table with only two, long-ish columns. I want the display the
I am creating a table that has a total of five columns. DUring the
I have created table and inserted values as below. create table mytable (id INT,
i created a table in the database (mysql),and i write a code for inserting

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.