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?
You want to use JS string templates ('template literals'), ie strings in which JS expressions (eg. plain variables, as in your case) are interpolated:
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.