Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!