admin管理员组文章数量:1323736
I've two separate HTML file and .js file. I have a calculate method which return the result in the Javascript file.
My question is how to set a textbox value from a Javascript return value. Or at least from a separate Javascript file. Initially I tried below which doesn't work as Javascript and html are separated.
function Calculate(ch)
{
//...
document.getElementById('Input').value = resultValue;
}
I've two separate HTML file and .js file. I have a calculate method which return the result in the Javascript file.
My question is how to set a textbox value from a Javascript return value. Or at least from a separate Javascript file. Initially I tried below which doesn't work as Javascript and html are separated.
function Calculate(ch)
{
//...
document.getElementById('Input').value = resultValue;
}
Share
Improve this question
edited May 25, 2020 at 9:15
Brian Tompsett - 汤莱恩
5,89372 gold badges61 silver badges133 bronze badges
asked Mar 18, 2011 at 12:11
CharithJCharithJ
47.6k20 gold badges126 silver badges137 bronze badges
3
- is 'Input' the id of the textbox? – Tim B James Commented Mar 18, 2011 at 12:14
- Try using an alert box with your method in it. Also setting up a simple example on a site like jsfiddle helps us out a lot. – Timothy Ruhle Commented Mar 18, 2011 at 12:19
- can you put up the relevant part of the HTML file? – Dave Everitt Commented Mar 18, 2011 at 12:29
3 Answers
Reset to default 1eval is the soution for my problem. Input.value = eval(Calculate(ch))
try to define the js-file in the bottom of your html-file (near the </body>). if you defined it above the targeted element its unknown. this may help.
felix
Access textarea contents using the innerHTML
property, not the value
property.
function Calculate(ch) {
//...
document.getElementById('Input').innerHTML = resultValue;
}
本文标签: Set HTML textbox value from Javascript function return valueStack Overflow
版权声明:本文标题:Set HTML textbox value from Javascript function return value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742118949a2421602.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论