My idea is to add rows to a table with an "onclick" event in them. As you can see, in "var table" I create the "tr, td" and I pass the styles. So far, no problem, but when I launch it gives me an error of the type "Uncaught SyntaxError: Unexpected token}"
It seems that everything is a matter of the way I add the "onclick" to "table", because passing values by hand to insertPrefix (prefixFinal) works and "pickPrefixes" paints all the rows of the table well; it only fails when I click on any of the rows giving me the error mentioned above. The values "revision, revision2 and revision3" are strings, so I do not think that is the problem.
HTML:
<div class="modal-body">
<div class="container">
<h2>Filtro de Prefijos</h2>
<p>Escriba en el campo "Buscar" para realizar un filtrado de opciones</p>
<input class="form-control" id="myInputPrefix" type="text" placeholder="Buscar..">
<br>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Resultados</th>
</tr>
</thead>
<tbody id="myTablePrefix">
</tbody>
</table>
</div>
</div>
I have the following functions:
function recogerPrefijos(revision, revision2, revision3) {
var prefijoFinal = "PREFIX" + revision + ":" + revision2;
prefijoFinal = prefijoFinal.toString();
var tabla = "<tr><td style=\"max-width:50px; padding:10px;\"><a class=\"list-group-item list-group-item-action primary-color\" id=\"list-home-list\" data-toggle=\"list\" href=\"#list-home\" role=\"tab\" aria-controls=\"home\" title=\"Select\" data-dismiss=\"modal\" href=\"#\" onclick=\"insertarLinkPrefijo(\" + prefijoFinal + \")\">" + revision + ": " + revision2 + "</a></td></tr>";
var table = document.getElementById("myTablePrefix");
var row = table.insertRow(contadorRecogerPrefijos);
row.innerHTML = tabla;
contadorRecogerPrefijos++;
return prefijoFinal;
}
function insertarLinkPrefijo(prefijoFinal) {
var sentencia = prefijoFinal;
var editor = document.getElementsByClassName("CodeMirror-line");
editor[0].textContent = sentencia;
}
Thank you very much