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.

HTML
<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
Posted
Updated 25-Jun-21 12:34pm
v3

1 solution

Try this:

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


and in javascript

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


hope it helps :)
   
Comments
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