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

208
Vistas
Pass a value in document.write

I have a <script> that creates a tagId value.

Currently, it will display as document.write(tagId);

I want to place tagId in a <form> as:

<input type="text" name="" value="tagId">

Example, something like:

document.write(< input type="text" name="" value="tagId" >);

How can I place the tagID value to insert in the text form?

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

0

You want to use JS string templates ('template literals'), ie strings in which JS expressions (eg. plain variables, as in your case) are interpolated:

document.write(`<input type="text" name="" value="${tagId}">`);

You have to use backticks (``) as string delimiters. The expression(s) are referenced per ${<expression_goes_here>}. The expression is serialized as it would elsewhere in the code.

See here (MDN docs) for more info.

about 4 years ago · Juan Pablo Isaza Denunciar

0

I don't know if you have a specific reason for using document.write, the better approach would be to create an element and append it to a div in your document

const container = document.getElementById("addForm")
// Create element:
var input = document.createElement("input");
var tagId = "your tag ID"
input.type = "text";
input.name = ""
input.value = tagId

// Append to body:
container.appendChild(input);
<div id="addForm"></div>
    

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