Display span tag value in text file
I am displaying the value using span tags;
Js
<script>
window.onload = function () {
document.getElementById('tag').innerHTML = 122;
};
</script>
Html
<div id="tag"></div>
The value is 122
displayed on the screen. But I want to show the value 122
in text filed
. How can i do this?
+3
source to share
2 answers
You can just add input to DOM like <input type="text" id="tag">
and save
javascript as window.onload = function () {
document.getElementById('tag').value = 122;
};
This will do your job.
OR While keeping your code, you can do it like below:
HTML:
<div id="tag"></div>
JS:
<script type="text/javascript">
window.onload = function(){
// create a textfield dynamically, say it is "text"
document.getElementById('tag').appendChild(text);
}
</script>
0
source to share