0

I have

var  table = "<tr><td><input type='hidden' class='hid_id' value='"+id+"' /> "+id+
"</td><td>"+document.getElementById("name_"+id).value+
"</td><td>"+document.getElementById("price_"+id).value+
"</td><td><input type='text' id='qua_"+id+
"' value='1' disabled='disabled' /></td><td><button>more</button></td></tr>";

to add to table when user click Addbutton

  <table id="tbForm1"  border="1">
         <tbody>
         </tbody>
  </table>

But I want store it (var table) and assign to other one variable and all row when user click add. How I can ?

Edit I don't know syntax of JavaScript but if it's PHP, I mean:

  $ba .= 'a';
  if(click=='add'){
   $ba .='b';
  }
  echo $ba; //outup ab
Slava Vedenin
  • 58,326
  • 13
  • 40
  • 59
Songs
  • 267
  • 1
  • 2
  • 14

1 Answers1

0

As Vohuman mentioned use that function to create dynamic row with an Id and use below to add that row to another table.

var x =document.getElementById("tbForm1").getElementsByTagName('tbody');
x.innerHTML = generateRow(id);

Also refer to this to add subsequent rows

How to insert row in HTML table body in javascript?

Community
  • 1
  • 1
pratikpawar
  • 2,038
  • 2
  • 16
  • 20