...

View Full Version : Undefined array



dazza7
02-19-2008, 01:07 PM
Hi,

Having problems with the below script, I need to get the productDescription which matches the entry (orderProductArray) after it it is entered.

The Enter Item quantity prompt has the have the item description that matches the item that was previous entered.

I then need to output the item no entered, quantity and the matching product description.

The results of my script give an Undefined message.

Help appreciated.


var productCodes = ['a-23-009', 'k-246-07', 'd-555-01', 'n-87-012', 'u-521-08', 't-99-002'];
var productDescriptions = ['Superslurry electric blender', 'Apple - iPod (second-hand)', 'CoziNap nylon duvet tog 2', 'Headbanger mini hi-fi 20W', 'MagiBoot shoe cleaning kit', 'The PushmiPulu lawnmower'];

var orderProductArray = new Array();
var orderQuantityArray = new Array();

// indentify number of items
itemstobeOrdered = parseFloat(window.prompt('Enter the number of different items to be purchased',''));

// for loop to allow entry of items and quantities
for (var count = 0; count < itemstobeOrdered ; count = count + 1)
{
orderProductArray[count] = window.prompt('Enter Item No', '')
// Quantity Prompt
orderQuantityArray[count] = window.prompt('Enter Item quantity ' + productDescriptions[orderQuantityArray], '')
};
for (var count = 0; count < itemstobeOrdered; count = count + 1)
{
document.write('Item no: ' + orderProductArray[count] + 'Item Desc: ' + productDescriptions[orderQuantityArray] +
'Quantity: ' + orderQuantityArray[count] + '<BR>')
}

Kor
02-19-2008, 01:43 PM
...
orderProductArray[count] = Number(window.prompt('Enter Item No', ''))
// Quantity Prompt
orderQuantityArray[count] = window.prompt('Enter Item quantity ' + productDescriptions[orderProductArray[count]], '')
};
for (var count = 0; count < itemstobeOrdered; count = count + 1)
{
document.write('Item no: ' + orderProductArray[count] + 'Item Desc: ' + productDescriptions[orderProductArray[count]] +
'Quantity: ' + orderQuantityArray[count] + '<BR>')
}
...


But document.write() is not a dynamic method. You should use DOM methods or at least the innerHTML method to write something within a loop.

dazza7
02-19-2008, 10:06 PM
Thanks for the reply, spot on.:thumbsup:

How would I now add the quantities and price to give an overall order value?
I have tried another for loop but keeping getting underfined, so by my reckoning the code must need to be in the same for loop ?? but what code & where to specify is loosing me.

_Aerospace_Eng_
02-19-2008, 10:20 PM
I'm guessing this is homework. You along with the many others are doing similar programs.
http://www.codingforums.com/showthread.php?t=133303

dazza7
02-19-2008, 10:50 PM
Hi,

Looked at the previous posts and I got my head around those questions, stumped on how to calculate totals after the below.

orderProductArray[count] = Number(window.prompt('Enter Item No', ''))
// Quantity Prompt
orderQuantityArray[count] = window.prompt('Enter Item quantity ' + productDescriptions[orderProductArray[count]], '')
};
for (var count = 0; count < itemstobeOrdered; count = count + 1)
{
document.write('Item no: ' + orderProductArray[count] + 'Item Desc: ' + productDescriptions[orderProductArray[count]] +
'Quantity: ' + orderQuantityArray[count] + '<BR>')
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum