开发者

Set HTML textbox value from Javascript function return value

开发者 https://www.devze.com 2023-02-17 10:51 出处:网络
I\'ve two separate HTML file and .js file. I have a calculate method which return the result in the Javascript file.

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 se开发者_StackOverflow中文版parated.

function Calculate(ch) 
{
    //...
    document.getElementById('Input').value = resultValue;
}


eval 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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消