Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Undefined array

  1. #1
    New to the CF scene
    Join Date
    Feb 2008
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Undefined array

    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.
    Code:
    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>')	
    }
    Last edited by Kor; 02-19-2008 at 02:31 PM. Reason: wrap the code [code][/code]

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Code:
    ...
    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.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • Users who have thanked Kor for this post:

    dazza7 (02-19-2008)

  • #3
    New to the CF scene
    Join Date
    Feb 2008
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thanks for the reply, spot on.

    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.

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    I'm guessing this is homework. You along with the many others are doing similar programs.
    http://www.codingforums.com/showthread.php?t=133303
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    New to the CF scene
    Join Date
    Feb 2008
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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>')
    }
    Last edited by dazza7; 02-20-2008 at 12:00 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •