Our site www.viart.com site is operated by latest Viart Shop 5 with default Clear design
Topic Information
JackAndCoke
JackAndCoke
I have a form which contains two list boxes. List box 2 is a child of list box 1.
 
Using JavaScript in an onChange event, when a user selects something in list box 2, I am trying to call up the selectedIndex of listbox 1.
 
I tried getting it it via “parent” attribute but had no luck, as the result is always “undefined.” So I’m trying to get it by {property_parent_id####_####}.
 
I am trying to get the selectedIndex of listbox 1, named "{property_parent_id6385_6773}", but I need it dynamically, as, for another product, it might be "{property_parent_id7845_8946}"
 
{form_id} value is 6385
{property_id} is listbox 2, and in this example, the value is 6773
{property_parent_id6385_6773} value is 6765, and in this example, this refers to listbox 1
 
When I hard-code or semi-hard code it for testing, the following methods work:
 
this.form.property6385_6765.selectedIndex;
and
this.form.property{form_id}_6765.selectedIndex;
 
But, when I try to do it dynamically within my code, I have problems. I'm not JavaScript savvy, so I think it's a syntax issue.
 
This is my current, working code in an onChange event:
=================================
var FrameNo = '01';//ENTER FRAME NUMBER
var ImagePath = 'images/GlassesBrand/Rx/GlassesTest/';//ENTER PATH TO IMAGES
var ImageNamePrefix = 'GlassesTest-XL';//ENTER NAMING CONVENTION
// This changes the IMAGE hyperlink to larger image to match user's selection
document.getElementById('blackImg').href=ImagePath + 'Large/' + ImageNamePrefix + '-Frame' + FrameNo + '-Lens' + this.form.property{form_id}_{property_id}.options[this.form.property{form_id}_{property_id}.selectedIndex].text.substring(0,2) + '.jpg';
=================================
 
The change I want to make, is that I don't want to have to hard-code "FrameNo." I want to call that dynamically within the onChange event for listbox 2, by looking up the selectedIndex of listbox 1.
 
From my notes:
var FrameBox = [this.form.property_parent_id6385_6773.value]; //WHICH EQUALS "6765"
var FrameNo = 'this.form.property' + {form_id} + '_' + FrameBox + '.selectedIndex';
 
//RESULTS IN:
 
http://www.companyname.com/images/GlassesBrand/Rx/GlassesTest/Large/GlassesBrand-GlassesTest-XL-Framethis.form.property6385_ 6765.selectedIndex-Lens02.jpg
 
WHEREAS, an example of the result I am seeking is:
 
http://www.companyname.com/images/GlassesBrand/Rx/GlassesText/Large/GlassesBrand-GlassesTest-XL-Frame1-Lens02.jpg
 
Any help is greatly appreciated.