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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:45:33+00:00 2026-06-01T18:45:33+00:00

I am adding a row to a table. In one of the cells in

  • 0

I am adding a row to a table. In one of the cells in the row is an input which I want to make an ajax call. However, I am having a problem with passing the value of the input.

I’ve illustrated the problem here:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <script language="javascript">
      function addElement(){
        var id = 0;
        var tbl = document.getElementById('myTable');
        var rowInd = document.getElementById('row1').rowIndex;
        rowInd++;
        var row0 = tbl.insertRow( rowInd );
        var cell = row0.insertCell(0);
        //	cell.innerHTML = '<input type="text" id="myInput'+id+'" value="hello world" onkeyup="alert( '+this.value+' );" />';
        // acts as expected:  hello world
        //	cell.innerHTML = '<input type="text" id="myInput'+id+'" value="hello world" onkeyup="makeAjaxRequest( \'value='+this.value+'\' )" />';
        // Outputs:  value=undefined
        var theId = "myInput"+id;
        //	cell.innerHTML = '<input type="text" id="myInput'+id+'" value="hello world" onkeyup="makeAjaxRequest( \'value='+document.getElementById( theId ).value+'\' )" />';
        // Output:  Object required
        cell.innerHTML = '<input type="text" id="myInput'+id+'" value="hello world" onkeyup=" function(){ makeAjaxRequest( \'value='+this.value+'\' ) }" />';
        // Nothing happens
      }

      function makeAjaxRequest( val ){
        alert( val );
      }
    </script>
  </head>

  <body>
    <span onclick="addElement()">
      Click me
    </span>
    <br /><br />
    <table id="myTable">
      <tr id="row1"><td>hello</td></tr>
    </table>
  </body>
</html>

It’s going straight to an ajax call, so I need to be able to access either the object or the value so that I do my search. Any help is appreciated.

  • 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-01T18:45:35+00:00Added an answer on June 1, 2026 at 6:45 pm

    Thanks for making me discover insertRow, rowIndex and insertCell!

    Btw, you’re complicating your life for nothing.

    cell.innerHTML = '<input type="text" id="myInput'+id+'" value="hello world" onkeyup=" function(){ makeAjaxRequest( \'value='+this.value+'\' ) }" />';
    

    Here is the correct way (DOM-compatible, without innerHTML evil, blablabla):

    var input = document.createElement('input')
    input.type = 'text'
    input.id = 'myInput' + id
    input.value = 'hello world'
    input.onkeyup = function() {
        makeAjaxRequest(this.value) // this is how to make it work
    }
    cell.appendChild(input) // or use replaceChild depending on your needs
    

    The problem when you pass 'value=' + this.value is that you’re passing the following value: value=hello world.

    The other problem is that for inline event handlers (like the onkeyup in the HTML) is that you don’t need to wrap in a function. The following would work:

    cell.innerHTML = '<input type="text" id="myInput'+id+'" value="hello world" onkeyup="makeAjaxRequest( this.value );" />';
    

    I haven’t tested, but I suspect that by wrapping in another function, the this is different. Thus why it can’t work.

    To avoid any ambiguity, don’t use HTML event handlers.

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

Sidebar

Related Questions

Which method is preferred for adding a row to a table? var tr =
I'm having problems adding a new table row by clicking the link_to_add function link.
Is there an option to make one row in swt table not editable after
I'm adding a select box to a form by cloning the current table row,
Adding the row one by one in the button click.. (i tried but its
I am adding a new blank row to a dojox.grid.DataGrid, and want to focus
I am adding an activity indicator in each row of table. The issue is
I am trying to animate a table row sliding up, then adding a new
i have 2 tables, i want to add rows from one table to another,
My c# button adding some data in one table. how can i get id

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.