0

I have a large program with a form where information fills and updates based on other information. It worked one-day, the next my field value returns null. There are no error messages. I was looking for a generic list of "things to check."

Among other things, the form takes in 2 numbers, multiplies them, and returns the Sum. The variable for quantity is always returning NULL.

function calcprod(form, elem, val, theID) {
  var theForm = document.forms[form];
  var price = theForm['proforma_prod_lines_price_unit'].getAttribute('value');
  var quantity = theForm['proforma_prod_lines_num_unit'].getAttribute('value');
  prodTotal = Math.round((price * quantity) * 100) / 100;
  console.log(price + " x " + quantity + " = " + prodTotal);
  theForm[concat('proforma_prod_lines_total')].setAttribute('value', prodTotal);
}
<form name="status" id="status" action="?tab=proforma" method="post"  >
<input type="text" name="proforma_prod_lines_num_unit" id="proforma_prod_lines_num_unit" value="" onkeyup="calcprod('proforma_status_update', this.id, this.value,'')" />
<input name="proforma_prod_lines_price_unit" type="text" id='proforma_prod_lines_price_unit' value="" onkeyup="calcprod('proforma_status_update', this.id, this.value,'')" />
<input name="proforma_prod_lines_total" type="text" value="" readonly />
</form>
Lisa Baird
  • 33
  • 7
  • 4
    If you want the value that the user entered into the form, use `.value`, not `.getAttribute('value')` – Barmar Apr 04 '22 at 19:52
  • Your javascript code is referencing a form, however there is no form in your example. – James Apr 04 '22 at 19:53
  • Does it really return `null` or does it return an empty string? – Barmar Apr 04 '22 at 19:53
  • https://stackoverflow.com/questions/11973678/difference-between-element-value-and-element-getattributevalue – James Apr 04 '22 at 19:56
  • Changing ('value') to .value didn't work, but changing the entire line to document.getElementById("proforma_prod_lines_num_unit").value; did work. Can someone explain why or provide a link? It worked for a few months using the ('value'). – Lisa Baird Apr 04 '22 at 20:22
  • Thank you, the answer is easy to find when you know the question. – Lisa Baird Apr 04 '22 at 20:29

0 Answers0