2

I have the following code with JQuery and i get "Uncaught SyntaxError: Unexpected identifier" error in line var nueva fila = $(document.createElement('tr'));.

function add_fields_for_membresias(event) {
var usuario_id = $('#cbx_miembro').val();

var usuario_nombre = $('#cbx_miembro :selected').text();

var rol_value = $('#cbx_rol').val();

var posicionRolEnLaTabla = $('#tb_membresias tbody tr').length;

var columna_usuarioNombre = $('td');

columna_usuarioNombre.html = usuario_nombre;

var columna_rol = $('td');

columna_rol.html("<input id='equipo_membresias_attributes_" + posicionRolEnLaTabla + "_usuario_id' name='equipo[membresias_attributes][" + posicionRolEnLaTabla + "][usuario_id]' readonly='readonly' type='hidden' value='" + usuario_id + "\'>" +
"<input id='equipo_membresias_attributes_" + posicionRolEnLaTabla + "_supervisor' name='equipo[membresias_attributes][" + posicionRolEnLaTabla + "][administrador]' readonly='readonly' type='hidden' value='" + rol_value + "\'>" +
"<input id='equipo_membresias_attributes_" + posicionRolEnLaTabla + "_id' name='equipo[membresias_attributes][" + posicionRolEnLaTabla + "][id]' readonly='readonly' type='hidden'>" +
"<input id='equipo_membresias_attributes_" + posicionRolEnLaTabla + "__destroy' name='equipo[membresias_attributes][" + posicionRolEnLaTabla + "][_destroy]' type='hidden' value='false'>");

var columna_opciones = $('td');

columna_opciones.html("<input class=\"btn btn-mini\" onclick=\"remove_fields(this);\" type=\"button\" value=\"Quitar\">");

var nueva fila = $('tr');

nueva_fila.append(columna_usuarioNombre);
nueva_fila.append(columna_rol);
nueva_fila.append(columna_opciones);

$('#tb_membresias tbody').append(nueva_fila);
}

Somebody can help me?

I tryed also with:

"<input class=\"btn btn-mini\" onclick=\"remove_fields(this);\" type=\"button\" value=\"Quitar\">"
4
  • 1
    Where specifically are you getting this error? Commented Sep 14, 2013 at 16:58
  • 1
    The error doesn't belong to the posted code. Commented Sep 14, 2013 at 17:00
  • Looks fine to me. check here jsfiddle.net/J6BWc Commented Sep 14, 2013 at 17:00
  • Edit: I posted the entire function and put in where line get the error. Commented Sep 14, 2013 at 18:21

1 Answer 1

2

You should use

$('tr');

to create a tr element, instead of

$(document.createElement('tr'));

because, you are using jQuery and jQuery will take care of that. To create any element using jQuery you just supply the name of that element/tag, for example, to create a td you can use

var td = $('td');

for a div, just use

var div = $('div');

That's it.

Update: In your code you have

var nueva fila = $(document.createElement('tr'));

here, nueva fila is not a valid variable name, it should be a single word, without any spaces, like

var nuevafila = $('tr');

or you can use

var nueva_fila = $('tr');

Check Variables on MDN.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, i do it, but i keep getting the same error in the same line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.