2

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;
}
3
  • is 'Input' the id of the textbox? 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. Commented Mar 18, 2011 at 12:19
  • can you put up the relevant part of the HTML file? Commented Mar 18, 2011 at 12:29

3 Answers 3

1

eval is the soution for my problem. Input.value = eval(Calculate(ch))

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

I tried but not working. If I call normal javascript function that's working. So javascript file is properly definied I think but this perticular functionality.
0

Access textarea contents using the innerHTML property, not the value property.

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

2 Comments

I tried but not working. My "Input" text box is in a table inside a form. Is that an issue?
Is it an <input> or a <textarea>?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.