javascript add row to table

1
0
-1

Hey I just started to work on a javascript to add a row to a table so later on i can extend the script with the logic to add content of fields to the table in that row. I created a table called dataTable in the form.

two buttons with the code:

  1. simpel1: <INPUT type="button" value="Add Row" onclick="addRow('dataTable');" />
  2. simpel2: <INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable');" />

added a html widget with the following code:

  1. <SCRIPT language="javascript">
  2. function addRow(tableID) {
  3. var table = document.getElementById(tableID);
  4. var rowCount = table.rows.length;
  5. var row = table.insertRow(rowCount);
  6. var cell1 = row.insertCell(0);
  7. var element1 = document.createElement("input");
  8. element1.type = "checkbox";
  9. element1.name="chkbox[]";
  10. cell1.appendChild(element1);
  11. var cell2 = row.insertCell(1);
  12. cell2.innerHTML = rowCount + 1;
  13. var cell3 = row.insertCell(2);
  14. var element2 = document.createElement("input");
  15. element2.type = "text";
  16. element2.name = "txtbox[]";
  17. cell3.appendChild(element2);
  18. }
  19. function deleteRow(tableID) {
  20. try {
  21. var table = document.getElementById(tableID);
  22. var rowCount = table.rows.length;
  23. for(var i=0; i<rowCount; i++) {
  24. var row = table.rows[i];
  25. var chkbox = row.cells[0].childNodes[0];
  26. if(null != chkbox && true == chkbox.checked) {
  27. table.deleteRow(i);
  28. rowCount--;
  29. i--;
  30. }
  31. }
  32. }catch(e) {
  33. alert(e);
  34. }
  35. }
  36. </SCRIPT>

If i run the process locally it`s not working, how can this be?

Comments

Submitted by rafa brito on Wed, 05/27/2015 - 14:25

Hi,

I do that in a 5.10 of studio version and i dont have a problem with that, but i have a question about that...

How i can save this table in a arraylist variable from a conector script?

It is possible? Can you give a example?

Regards!

No answers yet.
Notifications