简体   繁体   中英

document.getElementById(“toai”).innerHTML = document.getElementById(“toai”).value

<script>
function toai()
{
var Fr_amt_invt  = document.getElementById("Fr_amt_invt").value;
var Re_amt_invt  = document.getElementById("Re_amt_invt").value;
var totaltoai = +Fr_amt_invt + +Re_amt_invt;
document.getElementById("toai").innerHTML=+totaltoai;
}

</script>

function toai() result is in .innerHTML i want result in .value format so that it use in form input.

Instead of doing document.getElementById("toai").innerHTML=+totaltoai; in the toai() function you can return the value.

<script>
function toai()
{
var Fr_amt_invt  = document.getElementById("Fr_amt_invt").value;
var Re_amt_invt  = document.getElementById("Re_amt_invt").value;
Fr_amt_invt = parseFloat(Fr_amt_invt);
Re_amt_invt = parseFloat(Re_amt_invt);
var totaltoai = (Fr_amt_invt + Re_amt_invt);
totaltoai = parseFloat(totaltoai);
//document.getElementById("toai").innerHTML=+totaltoai; // delete this
return totaltoai;
}

Then you can do document.getElementById('some-inputs-id').value = toai();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM