-4

I have a code very similar to this one, perform calculations and present the values ​​in textarea fields. I would like to know how you could pass these values ​​to a field like:

  <form role="form">
  <div class="form-group col-md-3">
  <label for="thingsId">Numbers of things</label>
  <input type="text" class="form-control" name="thingsName" id="thingsId"  >
  </div>

And not this:

<td><textarea row="1" type="number" id="thingsId" name="thingsName"></textarea></td>

This code uses exactly the same conditions, but I would like a result that wasn't in a textarea

http://jsfiddle.net/1wrnL3jp/5/ Topic of discussion: calculating form field input value from other values with onfocus

banana
  • 31
  • 8

2 Answers2

0

Your question is very bad formulated.

I looked at your fiddle and you are setting the innerHTML of the textarea. You should set the value of the textarea. Please invest more time on w3schools or mdn.

I hope this helped, good luck!

Laurent Dhont
  • 658
  • 4
  • 17
  • Thanks, i solved this problem. My question was basically how to pass the value of a getelementbyid to input field. I simply resolved by changing from document.getElementById ('thingsID'). InnerHTML to document.getElementById ('thingsID'). Value – banana Dec 12 '19 at 23:20
0

Solved changing from document.getElementById ('thingsID'). InnerHTML to document.getElementById ('thingsID').value

In Example:

function myCalc() {
var num1 = document.getElementById('WG_Collected').value;
var num2 = document.getElementById('Proof').value;
var PG_Collected = parseFloat(num1) * parseFloat(num2)/100;
document.getElementById('PG_Collected').innerHTML = PG_Collected.toFixed(2);
}

document.getElementById("WG_Collected").addEventListener("change", myCalc, true);
document.getElementById("Proof").addEventListener("change", myCalc, true);

Change to:

function myCalc() {
var num1 = document.getElementById('WG_Collected').value;
var num2 = document.getElementById('Proof').value;
var PG_Collected = parseFloat(num1) * parseFloat(num2)/100;
document.getElementById('PG_Collected').value= PG_Collected.toFixed(2);//().value//
}

document.getElementById("WG_Collected").addEventListener("change", myCalc, true);
document.getElementById("Proof").addEventListener("change", myCalc, true);
banana
  • 31
  • 8