Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

187
Vistas
How to concatenate a variable with string text for displaying as placeholder of an input

I have this script for adding new input field when user click on a link with id of add:

$(document).ready(function() {
            var i = 1;
            $('#add').click(function(){
                i++;
                $('#dyanimc-field').append("<input type='text' name='tag_name[]' value='' class='form-control' id='tagInput' placeholder='Tag name'+i>");
            });
 });

Now this works fine and properly adds a new input field but I want the placeholder of this input to be showing the value of i variable next to the Tag name text.

So the inputs would have these placeholder:

capture

Therefore I tried this placeholder='Tag name'+i> but this is wrong because it does not return any i variable value!

So how to concatenate a variable with string text for displaying as placeholder of an input correctly?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try this

$(document).ready(function() {
    var i = 1;
    $('#add').click(function(){
        i++;
        $('#dyanimc-field').append("<input type='text' name='tag_name[]' value='' class='form-control' id='tagInput' placeholder='Tag name " + i.toString() + "'>");
    });
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda