[英]Populating the data from JavaScript to textBox
I have a text box where i need to load the data when form is loaded. 我有一个文本框,在加载表单时需要在其中加载数据。 In "G6data" variable i am getting the value 100 but it is not getting populated in G6 text box. 在“ G6data”变量中,我得到的值是100,但未在G6文本框中填充它。 How can i populate the data which i got into input box using getElementByID. 如何使用getElementByID填充输入框中的数据。 Please help 请帮忙
<!DOCTYPE html>
<html>
<body onload="myFunction()">
<input type="text" id="f6" value="5000" />
<input type="text" id="G6" value="" />
<button >Try it</button>
<script>
function myFunction()
{
var F6=document.getElementById("F6").value;
var as6=calculateAS6(F6);
var as4=CalculateAS4(as6);
var G6data=AveragePercentage(as6,as4);
document.getElementById("G6").innerHTML=G6data;
}
</script>
</body>
</html>
You have mistake in Input element and for give value to any text box we use .value
insted of .innerHTML
. 您在Input元素中输入了错误,并且要为我们使用.innerHTML
.value
insted赋予任何文本框值。
Use this code 使用此代码
<html>
<body onload="myFunction()">
<input type="text" id="f6" value="5000" />
<input type="text" id="G6" value="" />
<button >Try it</button>
<script>
function myFunction()
{
var F6=document.getElementById("f6").value;
var as6=calculateAS6(F6);
var as4=CalculateAS4(as6);
var G6data=AveragePercentage(as6,as4);
document.getElementById("G6").value=G6data;
}
</script>
</body>
</html>
它应该是value
document.getElementById("G6").value=G6data;
There is a simple problem here 这里有一个简单的问题
<input type="text" id="f6" value="5000" />
Your id here is 'f6' while you are trying to fetch element with an id of 'F6' here 当您尝试在此处获取ID为“ F6”的元素时,此处的ID为“ f6”
var F6=document.getElementById("F6").value;
and use value instead of innerHTML here 并在此处使用值而不是innerHTML
document.getElementById("G6").innerHTML=G6data;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.