0

My english is not good but i need help please!!! I am adding dynamic rows to a table, within the row inputs used type checkbox. I need to use the onclick event checkbox, but I can't do.

 $('#nuevo').click(function() {

//adding a row

     var idusu = "<?php echo $idusuariologeado; ?>" ;
 var fila='<tr><td>&nbsp;</td>'+

 '<td><input name="idiomas_nombre[]" type="text" placeholder="Idioma" 
  class="form-control input-md"  /><input  name="idiomas_usu[]" type="text" 
   value="'+ idusu + '" > </td>'+

  '<td><input  name="" type="checkbox" value="1" ><input type="hidden" 
   name="idiomas_suficiencia[]" value="" /></td>'+

   '<td><input id="cb2"  name="" type="checkbox" onclick="updatebox()" 
   value="1" /><input type="text" name="idiomas_escritura[]"  /></td>'+

   '<td><input id="cb3"  name="" type="checkbox" value="1"  >
   <input type="hidden" name="idiomas_lectura[]" value="1" /></td>'+

   '<td align="center"><input id="cb4" name="" type="checkbox" value="1" >     
   <input type="text" name="idiomas_hablado[]" value="1" /></td></tr>';


 //row to table
$('#tab_logic').append(fila);




  });

the function I intend to use in the onclick

function updatebox()
{
var textbox = document.getElementById("idiomas_escritura");
var values = [];

if(document.getElementById('cb2').checked) {
    values.push("1");
}

if(document.getElementById('cb3').checked) {
    values.push("1");
}

if(document.getElementById('cb4').checked) {
    values.push("1");
}


    textbox.value = values.join(" ");
}

Please help me. Thank's

Sanjuktha
  • 1,065
  • 3
  • 13
  • 26
sebastianpe93
  • 71
  • 1
  • 1
  • 6

1 Answers1

1

there is no tag with id="nuevo", just add id attribute to any element

P. Ilyin
  • 761
  • 10
  • 28