Note that there are some explanatory texts on larger screens.

plurals
  1. POInserting rows with inputs in a table dynamically
    primarykey
    data
    text
    <p>I have built a function using jQuery to insert into a table a new row including some inputs, like textboxes, checkboxes and one button.</p> <p>This is the code I have:</p> <pre><code>$('#AddEntry').click(function () { var lastTrClass = $('tr:last').attr('class'); var textBoxTitle = '&lt;input id="titleid" type="text" value="" style="width: 100%; vertical-align: middle"&gt;'; var textBoxStartDate = '&lt;input id="StartDate" type="text" class="required DatePicker" value="" style="width: 100%; vertical-align: middle"&gt;'; var checkBoxSync = '&lt;input id="Sync" type="checkbox" checked="checked" disabled="disabled" value="true" style="vertical-align: middle"&gt;'; var lastDate = '&lt;input id="LastSyncDate" class="required DatePicker" type="text" value="" style="width: 100%; vertical-align: middle"&gt;'; var buttonEdit = '&lt;button id="btnEditar" class="EditButton icon_only text_only" style="vertical-align: middle;" type="button"&gt;Editar&lt;/button&gt;'; if (lastTrClass == 'gradeA odd') { $('#DataTable &gt; tbody:last').append("&lt;tr class='gradeA even'&gt;&lt;td&gt;#&lt;/td&gt;&lt;td&gt;" + textBoxTitle + "&lt;/td&gt;&lt;td&gt;" + textBoxStartDate + "&lt;/td&gt;&lt;td&gt;" + checkBoxSync + "&lt;/td&gt;&lt;td&gt;" + lastDate + "&lt;/td&gt;&lt;td&gt;" + buttonEdit + "&lt;/td&gt;&lt;/tr&gt;"); } else { $('#DataTable &gt; tbody:last').append("&lt;tr class='gradeA odd'&gt;&lt;td&gt;#&lt;/td&gt;&lt;td&gt;" + textBoxTitle + "&lt;/td&gt;&lt;td&gt;" + textBoxStartDate + "&lt;/td&gt;&lt;td&gt;" + checkBoxSync + "&lt;/td&gt;&lt;td&gt;" + lastDate + "&lt;/td&gt;&lt;td&gt;" + buttonEdit + "&lt;/td&gt;&lt;/tr&gt;"); } }) </code></pre> <p>As you can see in my code, I'm generating the inputs into a <code>var</code>, but my question is whether or not this is safe. Is my code vulnerable to a JS injection or something like that? Is there a better way to do this? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload