I’m trying to build a javascript array based upon user input. Users type in text in two fields, press a button and the array should be built in the backend. If the user presses the button again, another element should be added to the array. The Users will see the array elements appear on the screen in a Computed Field
I can get the first value into the array fine. It’s when the button is pressed a 2nd or more times that it doesn’t work:
Field on form:
FIELDName TipTextArray
ComputedField which displays the value from the TipTextArray field.
onLoad:
ThisDoc = document.forms[0];
Button onclick:
generateTipTextArray();
JS Header:
function generateTipTextArray(){
var tipArray = new Array();
if (ThisDoc.TipTextArray.value=="") {
tempVar = "Text[0] = [\"" + ThisDoc.TipTitle.value + "\",\"" + ThisDoc.TipText.value + "\"]";
ThisDoc.TipTextArray.value = tempVar;
tipArray[0] = tempVar;
}
else{
var i = tipArray.length;
i = i +1
alert("new array length" +i );
tempVar = "Text[" + i + "] = [\"" + ThisDoc.TipTitle.value + "\",\"" + ThisDoc.TipText.value + "\"]";
tipArray[i] = tempVar;
}
}