1
function saveForm() {

    var array = [];
    array.push(txtTName.value + "," + txtTNumber.value + "," + txtProjName.value + "," + getTotal());

    var scores = document.getElementById("scores");
    scores.innerHTML += "<br \>" + array[0] + array[1] + array[2];
}

Here's my code. So when a button is pushed it calls "saveForm()" which saves the values into an array and displays them. The first time its called it displays "xxxxx undefined undefined" the next time it calls "yyyyyy undefined undefined". Shouldn't it be returning "xxxxx yyyyy undefined"?

I'm only displaying elements 0,1, and 2 right now for testing purposes.

function saveForm(){

var array = [];
var list = txtTName.value + "," + txtTNumber.value + "," + txtProjName.value + "," + getTotal();
array.push(list);
var scores = document.getElementById("scores"); 
scores.innerHTML += "<br \>" + array[0] + array[1] + array[2];
}

Here's an edited version of saveForm(). The values don't really matter, I'm more wondering if there's a reason its only changing the first element. Do I need to create array outside of the function?

0

2 Answers 2

3
function saveForm() {
  var array = [];

  array.push(txtTNumber.value);
  array.push(txtTNumber.value);
  array.push(txtProjName.value);
  array.push(getTotal());

  document.getElementById("scores").innerHTML += "<br \>" + array.join(', ');
}
Sign up to request clarification or add additional context in comments.

Comments

0
var array = [];

function saveForm(){
....
}

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.