Click here to Skip to main content
15,040,212 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to use a JavaScript variable inside HTML tag , consider the following example.

<script> var tbIndx = 10 ;/script> 
<input type="text" name="someInput" value="?">

I want the attribute 'value' to have the value of the variable tbIndx instead of '?', so how to?

I tried ${tbIndx} and &{tbIndx}; but both didn't work.

Please help
Updated 25-Jun-21 12:34pm

1 solution

Try this:

in html
<input type="text" id="someInput" name="someInput"></input>

and in javascript

var tbIndx = 10;
document.getElementById("someInput").value = tbIndx;

hope it helps :)
Rick Medlin 29-Jun-21 2:23am
I'm fairly new to web development and this solved a huge problem for me. Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900