Ok, the naming works now, thanks for that.
Below is the new code, once a value "numba" has been inserted it produces the div's as it should, but nothing in the way of array's work, nor does the value of the Area (Length x Width). I am starting to think that I am way off track and the apparent arrays, are not existent, and the names just look like arrays. Could someone please point out whether or not they are arrays, and any other problems you may see.
For those who don't understand, this is what should happen...
- User Inputs amount of rectangles/squares to use within the calculator (it is to determine total yard size (minus house, garden etc), as it is generally not one single rectangle/square.
- User then adds a length and a width to each rectangle, the Area box is the sum of Length x Width. This is continued until they have filled in all Length and Width boxes.
- The sum of all Area boxes is established to produce a Total Area value.
Thanks again.
Code: Select all
function addElement() {
var lengtha = new Array;
var wideness = new Array;
var areaa = new Array;
var numba = document.getElementById('calculator').value;
if (numba > 10) {
$('<div style="height:30px;" valign="center" align="center">').append($('<font style="font-family:arial,verdana,sansserif;color:#FFFFFF;font-size:12px">Please enter in a value between 1 and 10</font>')).appendTo("#calcform").attr('id','Div'+counta);
}
var counta = 0;
while (counta < numba) {
$('<div style="height:30px;" valign="center" align="center">').append($('<font style="font-family:arial,verdana,sansserif;color:#FFFFFF;font-size:12px">Length <input type="text" onchange="editit();" id="lengtha['+counta+']" size="8" style="background: #79f27f;border: 1px solid #FFFFFF;font-family:arial,verdana,sansserif;"/> m x Width <input type="text" onchange="editit();" id="wideness['+counta+']" size="8" style="background: #79f27f;border: 1px solid #FFFFFF;font-family:arial,verdana,sansserif;"/> m = <input type="text" id="areaa['+counta+']" style="background: #79f27f;border: 1px solid #FFFFFF;font-family:arial,verdana,sansserif;" size="8"/> m²</font>')).appendTo("#calcform").attr('id','Div'+counta);
counta++;
}
document.getElementById('calculator').value = "";
}
document.getElementById('areaa['+counta+']').value= lengtha[counta] * wideness[counta];
var sum = 0;
for (i=1; i<=areaa.length; i++)
{
sum = sum + areaa[i];
document.getElementById('areatotal').value = sum;
}