繁体   English   中英

JavaScript语法-列表框onChange事件

[英]JavaScript Syntax - Listbox onChange Event

首先,请原谅我,因为我对JavaScript知之甚少,并且在不了解正确的术语和语法的情况下试图使某些东西正常工作。 我在CMS中称为“ ViArt”。 发生的很多事情都是由php处理的,而且我只能在ViArt中访问以将JavaScript添加到列表框的onChange事件中。

这是我要完成的工作:

该产品是太阳镜。 列表框1中的不同框架颜色由数字前缀指定。 每种镜框颜色都有30种不同的镜片颜色选项,这些镜片颜色在列表框2中选择。

使用当前代码,对于每个框架,我必须进入每个框架的JavaScript,并手动输入为该框架指定的数字前缀。

这是我当前的onChange事件中的工作代码:

=================================
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.substrin    g(0,2) + '.jpg';

===============================我想做的改变是我不想硬代码“框架编号”。 我想通过查找列表框1的selectedIndex动态地在onChange事件中调用它。

============================

在名为“ {property_id}”的列表框2的onChange事件中,我试图获取名为“ {property_parent_id6385_6773}”的列表框1的selectedIndex

{form_id}值为6385

{property_id}是列表框2,在此示例中,值是6773

{property_parent_id6385_6773}值是6765,在此示例中,它引用列表框1

{property_parent_id6385_6773}由php脚本等动态命名。 例如,在下一个表格中,它可以称为{property_parent_id6400_6800}。 因此,我尝试对JavaScript进行编程,以根据要使用的任何形式和列表框动态引用property_parent_id ##### _ #####。

当我对其进行硬编码或半硬编码以进行测试时,以下方法有效:

this.form.property6385_6765.selectedIndex;

this.form.property{form_id}_6765.selectedIndex;

我不知道语法,所以我认为在变量中声明一些内容可能有助于我获得所需的信息。

从我的笔记:

var FrameBox = [this.form.property_parent_id6385_6773.value];    //WHICH EQUALS "6765"
var FrameNo = 'this.form.property' + {form_id} + '_' + FrameBox + '.selectedIndex';  

结果是:

http://www.companyname.com/images/GlassesBrand/Rx/GlassesTest/Large/GlassesBrand-GlassesTest-XL-Framethis.form.property6385_6765.selectedIndex-Lens02.jpg

而我要寻找的结果的一个示例是:

http://www.companyname.com/images/GlassesBrand/Rx/GlassesTest/Large/GlassesBrand-GlassesTest-XL-Frame1-Lens02.jpg

=============================

总而言之,我知道我需要什么,但是我对语法没有足够的了解。

我知道最好用这样的措辞,但这对我来说是全新的。 从好的方面来说,我现在受到启发去学习JavaScript课程。

任何帮助将不胜感激。

这更多是经过计算的猜测,但值得一试。

this.form.property_parent_id{form_id}_{property_id}.options[this.form.property_parent_id{form_id}_{property_id}.selectedIndex].text

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM