• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

jquery - how to append input with name array to a row?

I'm setting up a form that will dynamically create a text field and append it to the table. The name of the text field is an array, so it contains brackets. The code below doesn't append the input field, rather, it spits back [object HTMLInputElement]. I'm assuming it's because of the brackets? Is there a way to do this?
//HTML
<table id="notesplus" cellpadding="0" cellspacing="0">
<thead></thead>
<tbody></tbody>
</table>

//JQUERY
$(document).ready(function() {
  $('input[id=addIt]').live('click', function() {
     addPlus();
  });
});

function addPlus() {
  var item = document.createElement("textarea");
  item.setAttribute("name", "section[0][aplus]"+mycount+"[notes]");

  var sRow1 = $('<tr>').appendTo('table#notesplus tbody');
  var sCell1 = $('<td>').html(item).appendTo(sRow1);
}

Open in new window

0
n00b0101
Asked:
n00b0101
1 Solution
 
leakim971PluritechnicianCommented:
may help : http://jsfiddle.net/3nbbn/

function addPlus() {
    $('table#notesplus tbody').append("<tr><td><textarea name='section[0][aplus]" + mycount + "[notes]'></textarea></td></tr>");
}

Open in new window

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now