Forum Moderators: open

Message Too Old, No Replies

Javascript SELECT populate function returning undefined elements

Returns infinate undefined elements

         

PSWorx

3:30 pm on Aug 17, 2006 (gmt 0)

10+ Year Member



This is something where you will need to view the actual project im working on, please leave me a personal message for more details.

Problematic js is as follows:

function populatePa()
{
if (!optionTest) return;
var box = document.forms['filters'].first;
var number = box.options[box.selectedIndex].value;
if (!number ¦¦ number==0) return;
var list = storeP[number];
var box = document.forms['filters'].fourth;
box.options.length = 0;
for(i=0;list.length;i+=2)
{
box.options[i/2] = new Option(list[i],list[i+1]);
}
}

JS Arrays (to populate "fourth" select list):

var storeP = new Array();
storeP['7'] = new Array(
'No Products available','');
storeP['16'] = new Array(
'No Products available','');
storeP['14'] = new Array(
'No Products available','');

storeP['21369'] = new Array(
'-- Products -- ','',
'Hyundai ImageQuest 32" LCD Screen','1');
storeP['3'] = new Array(
'No Products available','');
storeP['10'] = new Array(
'No Products available','');

storeP['8'] = new Array(
'-- Products -- ','',
'Dell Latitude C610 Laptop','3',
'HP Omnibook 6000 Laptop','7',
'Packard Bell Easynote R1 000 Laptop','6',
'Packard Bell Easynote W1 801 Laptop','5');
storeP['11'] = new Array(
'No Products available','');
storeP['9'] = new Array(
'No Products available','');
storeP['4'] = new Array(
'No Products available','');

If you have access to view the area in question, when choosing from the sections select list the script hangs populating the products select list, it will return the correct array but then appears to return and infinate number of undefined select option elements, this takes place on the 2 other seperate populate functions used (not listed here) named:

populatePa() < Listed above, populates according to first option

populatePb() < Populates according to second option
populatePc() < Populates according to third option

Origonal script was sourced from here to populate a secondary select list according to the option select in the first list, modified to handle up to three select lists (chaging the next level according to previous selection). This final piece is to display products according to section chosen (category, subcategory or subfilter/tree).

Please leave a sticky and i will give you more info.

TIA

garann

7:12 pm on Aug 17, 2006 (gmt 0)

10+ Year Member



I see a couple things that seem like they might be problematic.. As to the infinite nature of your results, this looks suspicious:

 for(i=0;[b]list.length;[/b]i+=2) 

That second bit should be the condition under which the loop ends, which is to say, something like

 for(i=0;[b]i<list.length[/b];i+=2) 
.

As far as getting undefined results, could it have anything to do with these guys:

storeP['7'] = new Array(
'No Products available','');
? I don't think you want quotes around the size of the array.

Hope some of that helps...

PSWorx

7:33 pm on Aug 18, 2006 (gmt 0)

10+ Year Member



My bad, reposted pointlessly u were right it was the missing condition i<list.length.

Totaly overlooked that when comparing to the origonal, dont understand how i managed to delete it either.

Thanks

[edited by: PSWorx at 7:38 pm (utc) on Aug. 18, 2006]