2

This is my HTML code:

<head>

</head>

<body>

   LIMIT<input id='limit' name='' value='' class=''>

   <button id='go' class=''>GO</button>

   TOTAL<input id='total' name='' value='' class=''>

   <script src='js/limitfor.js'></script>


</body>

And this is my JavaScript:

document.getElementById('go').onclick = function () {

 var limit = document.getElementById('limit').value;

 limit = parseFloat(limit);

 total = 0;

 for (i=0; i<=limit ;i++) {

     total = total + i;        

 };

};

If I alert the total, I can see that the function works, but I need the total to be in the textbox rather than in a pop up alert.

1

4 Answers 4

3

You will need to set the value of the input element:

document.getElementById("total").value = total;
Sign up to request clarification or add additional context in comments.

Comments

2

First select the particular element (i.e. total text field) in the form and set its value using assignment operator '='

document.getElementById("total").value=total;

1 Comment

If you could please edit your answer and explain what the code you're showing does, and why/how that code answers the question, it could really help.
0

Just assign the value in total text box after your for loop is completed

 var limit = document.getElementById('limit').value;

 limit = parseFloat(limit);

 total = 0;

 for (i=0; i<=limit ;i++) {

   total = total + i;        

};
document.getElementById("total").value = total; 

};

Comments

0

use document.getElementById(put id of the text area where you want to output your answer or result).value = answer(whatever is your answer or result you want to reflect in textbox or textarea)

enter image description here

Comments

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.