1 year ago

#374710

test-img

Lisa Baird

Reasons for getAttribute returning Null

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>

javascript

setattribute

getattribute

0 Answers

Your Answer

Accepted video resources