Insert a row with javascript

Hello, I am currently trying to add a functionality which is to add a new row to a table records when the user presses a button on the above row...

I am trying to replicate inputs, but also objects (like a calendar, an image and an expression).

Probably there is some way of doing it with javascript, specifying my inputs/elements one by one.

What i wonder is if there is a way of simply copying the elements of the above row when the user presses a button. Is there any way to do this whithout having to specify which elements are on the row?

I guess you have some function that builds table records, and my guess would go for using some similar function....

Perhaps i could even use a list insert, and then reload my page, but i wonder if there is other way for doing it...

I don't know if i made myself understood, but hope so...

Best Regards,

Diogo C S Cordeiro
I managed a workaround using a button per line and the action list insert... But i still believe that javascript code for this would be a great extent (I just don't have enough time now to work on it...)

Best Regards,

Diogo C S Cordeiro
Hi Diogo,

You can get the DOM object for the table row either with document.getElementById('id of the row') or by getting the DOM object for the table and using something like var trs = table.getElementsByTagName('tr'); var row=tr.item(position);

You can then clone the DOM object and all its childs (which are the controls you want to replicate). So let's suppose you want to duplicate the last row... you could use something like:

function dupLastRow(tableId) {
var table = document.getElementById(tableId);
var trs = table.getElementsByTagName('tr');
var lastRow = trs.item(trs.length-1);
table.appendChild(lastRow.cloneNode(true)); // the "true" argument asks for all child nodes to be cloned too.

problems with this kind of approach:
- can lead to duplicate element IDs (which may lead to unpredictable behavior on subsequent getElementById() invocations)
- may re-run any cloned <script> elements (anyway it's not a good idea to have a <script> element for each table row)

The code in this post wasn't tested, so it might not work :) Anyway I hope it helps!

Best regards,
Miguel Ventura
I have a similar problem. In my case I want to convert a text into html. For exemple if someone writes: 
How are you?"
in the textarea, I want to save it like this:
"Hi!<br>How are you?" 
in my table.

I've been trying to use this function onkeypress
"function enter(){
var question=document.getElementById('wtAddQuestion_QuestionText').value;
question = question.replace(/\n/g,<br/>);
document.getElementById('wtAddQuestion_QuestionText').innerHTML = question;

Hi Janete, 

in that scenario, why not use CKEditor instead?


Now I have another problem, in IE in some cases the text appears with html tags. 

Hi Janete,

Why not do that post-processing server-side, when the data is actually being saved to the database?

Paulo Tavares
Hi again!
The situation is, I want to save the text with html and then show it. It works just fine, but when I use record lists it doesn't recognize the html and shows it's tags.
Hi Janete,

have you defined the expression inside the record list as "Escape Content" to "No"?

let us know more about it.

Miguel Antunes
Yes! That is the solution!
Many thanks!