javascript - JS: How to print elements in a for loop with distinct #ids? -


i want print out jquery, several html elements, , each element should have distinct #id.

my code output elements, don´t know how make them different.

<input type='button' onclick="generartabla(5)" name='submit' value='how many?'> <div id="output"></div>  function generartabla(cant) { var numero = 1; var celda = "mes <input type='text' name='nro"+numero+"'><br>"; ($i=0; $i<cant; $i++) {      $('#output').append(celda);     }      } 

each line should this:

mes <input type='text' name='nro1'><br> mes <input type='text' name='nro2'><br> mes <input type='text' name='nro3'><br> 

etc.

and right outputs this:

mes <input type='text' name='nro1'><br> mes <input type='text' name='nro1'><br> mes <input type='text' name='nro1'><br> 

here´s copy of code @ jsfiddle

put constructor inside loop , use loop variable

function generartabla(cant) {     ($i=0; $i<cant; $i++) {          var celda = "mes <input type='text' name='nro"+($i+1)+"'><br>";         $('#output').append(celda);     }      } 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -