-1

ユーザーが定義した 3 つの値を使用して、かなり単純な配列テーブルを作成しました。これら 3 つの値によって、変数の値が決まります。以前に同様のコードを書いたことがありますが、何らかの理由でこれが機能しない理由がわかりません。テーブルが大きいのでサイズが小さくてすいません…

var ssRidgeQty=document.getElementById("ssRidgeTrim").value;

var ssRidgeWidth=document.getElementById("ssRidgeWidth").value;

var ssRidgeColorUp;
if (ssColorChoice=="galvalume")
{
    ssRidgeColorUp="1";
}
else if (ssColorChoice=="Dark Gray" || ssColorChoice=="Antique Bronze" ||     ssColorChoice=="Rural Red" || ssColorChoice=="Dark Green" || ssColorChoice=="Fern Green")
{
    ssRidgeColorUp="2";
}
else if (ssColorChoice=="metallic copper")
{
    ssRidgeColorUp="3";
}
else if (ssColorChoice=="none" && ssRidgeQty>0)
{
    ssRidgeColorUp=0;
    alert ("please choose a ss color");
}
else
{
    ssRidgeColorUp="4";
}

var ssRidgeCap = new Array();
//retail, galvalume
ssRidgeCap [[0],[1],[14]] = 21.75;
ssRidgeCap [[0],[1],[16]] = 28.1;
ssRidgeCap [[0],[1],[18]] = 31.3;
ssRidgeCap [[0],[1],[20]] = 34.5;
ssRidgeCap [[0],[1],[22]] = 37.7;
ssRidgeCap [[0],[1],[24]] = 40.9;
ssRidgeCap [[0],[1],[26]] = 44.1;
ssRidgeCap [[0],[1],[28]] = 47.3;
ssRidgeCap [[0],[1],[30]] = 50.5;
ssRidgeCap [[0],[1],[32]] = 53.7;
ssRidgeCap [[0],[1],[34]] = 56.9;
ssRidgeCap [[0],[1],[36]] = 60.1;
ssRidgeCap [[0],[1],[38]] = 63.3;
ssRidgeCap [[0],[1],[40]] = 66.5;
//retail, Kynar
ssRidgeCap [[0],[2],[14]] = 25.85;
ssRidgeCap [[0],[2],[16]] = 31.3;
ssRidgeCap [[0],[2],[18]] = 34.9;
ssRidgeCap [[0],[2],[20]] = 38.5;
ssRidgeCap [[0],[2],[22]] = 42.1;
ssRidgeCap [[0],[2],[24]] = 45.7;
ssRidgeCap [[0],[2],[26]] = 49.3;
ssRidgeCap [[0],[2],[28]] = 52.9;
ssRidgeCap [[0],[2],[30]] = 56.5;
ssRidgeCap [[0],[2],[32]] = 60.1;
ssRidgeCap [[0],[2],[34]] = 63.7;
ssRidgeCap [[0],[2],[36]] = 67.3;
ssRidgeCap [[0],[2],[38]] = 70.9;
ssRidgeCap [[0],[2],[40]] = 74.5;
//retail, Metallic Copper
ssRidgeCap [[0],[3],[14]] = 26.55;
ssRidgeCap [[0],[3],[16]] = 35.3;
ssRidgeCap [[0],[3],[18]] = 39.4;
ssRidgeCap [[0],[3],[20]] = 43.5;
ssRidgeCap [[0],[3],[22]] = 47.6;
ssRidgeCap [[0],[3],[24]] = 51.7;
ssRidgeCap [[0],[3],[26]] = 55.8;
ssRidgeCap [[0],[3],[28]] = 59.9;
ssRidgeCap [[0],[3],[30]] = 64;
ssRidgeCap [[0],[3],[32]] = 68.1;
ssRidgeCap [[0],[3],[34]] = 72.2;
ssRidgeCap [[0],[3],[36]] = 76.3;
ssRidgeCap [[0],[3],[38]] = 80.4;
ssRidgeCap [[0],[3],[40]] = 84.5;
//retail, Syl-Poly
ssRidgeCap [[0],[4],[14]] = 22.5;
ssRidgeCap [[0],[4],[16]] = 28.9;
ssRidgeCap [[0],[4],[18]] = 32.2;
ssRidgeCap [[0],[4],[20]] = 35.5;
ssRidgeCap [[0],[4],[22]] = 38.8;
ssRidgeCap [[0],[4],[24]] = 42.1;
ssRidgeCap [[0],[4],[26]] = 45.4;
ssRidgeCap [[0],[4],[28]] = 48.7;
ssRidgeCap [[0],[4],[30]] = 52;
ssRidgeCap [[0],[4],[32]] = 55.3;
ssRidgeCap [[0],[4],[34]] = 58.6;
ssRidgeCap [[0],[4],[36]] = 61.9;
ssRidgeCap [[0],[4],[38]] = 65.2;
ssRidgeCap [[0],[4],[40]] = 68.5;
//Contractor, galvalume
ssRidgeCap [[1],[1],[14]] = 20.38;
ssRidgeCap [[1],[1],[16]] = 26.5;
ssRidgeCap [[1],[1],[18]] = 29.5;
ssRidgeCap [[1],[1],[20]] = 32.5;
ssRidgeCap [[1],[1],[22]] = 35.5;
ssRidgeCap [[1],[1],[24]] = 38.5;
ssRidgeCap [[1],[1],[26]] = 41.5;
ssRidgeCap [[1],[1],[28]] = 44.5;
ssRidgeCap [[1],[1],[30]] = 47.5;
ssRidgeCap [[1],[1],[32]] = 50.5;
ssRidgeCap [[1],[1],[34]] = 53.5;
ssRidgeCap [[1],[1],[36]] = 56.5;
ssRidgeCap [[1],[1],[38]] = 59.5;
ssRidgeCap [[1],[1],[40]] = 62.5;
//Contractor, Kynar
ssRidgeCap [[1],[2],[14]] = 25.2;
ssRidgeCap [[1],[2],[16]] = 30.5;
ssRidgeCap [[1],[2],[18]] = 34;
ssRidgeCap [[1],[2],[20]] = 37.5;
ssRidgeCap [[1],[2],[22]] = 41;
ssRidgeCap [[1],[2],[24]] = 44.5;
ssRidgeCap [[1],[2],[26]] = 48;
ssRidgeCap [[1],[2],[28]] = 51.5;
ssRidgeCap [[1],[2],[30]] = 55;
ssRidgeCap [[1],[2],[32]] = 58.5;
ssRidgeCap [[1],[2],[34]] = 62;
ssRidgeCap [[1],[2],[36]] = 65.5;
ssRidgeCap [[1],[2],[38]] = 69;
ssRidgeCap [[1],[2],[40]] = 72.5;
//Contractor, Meta1llic Copper
ssRidgeCap [[1],[3],[14]] = 25.85;
ssRidgeCap [[1],[3],[16]] = 34.5;
ssRidgeCap [[1],[3],[18]] = 38.5;
ssRidgeCap [[1],[3],[20]] = 42.5;
ssRidgeCap [[1],[3],[22]] = 46.5;
ssRidgeCap [[1],[3],[24]] = 50.5;
ssRidgeCap [[1],[3],[26]] = 54.5;
ssRidgeCap [[1],[3],[28]] = 58.5;
ssRidgeCap [[1],[3],[30]] = 62.5;
ssRidgeCap [[1],[3],[32]] = 66.5;
ssRidgeCap [[1],[3],[34]] = 70.5;
ssRidgeCap [[1],[3],[36]] = 74.5;
ssRidgeCap [[1],[3],[38]] = 78.5;
ssRidgeCap [[1],[3],[40]] = 82.5;
//Contractor, Syl-Poly
ssRidgeCap [[1],[4],[14]] = 21.75;
ssRidgeCap [[1],[4],[16]] = 28.1;
ssRidgeCap [[1],[4],[18]] = 31.3;
ssRidgeCap [[1],[4],[20]] = 34.5;
ssRidgeCap [[1],[4],[22]] = 37.7;
ssRidgeCap [[1],[4],[24]] = 40.9;
ssRidgeCap [[1],[4],[26]] = 44.1;
ssRidgeCap [[1],[4],[28]] = 47.3;
ssRidgeCap [[1],[4],[30]] = 50.5;
ssRidgeCap [[1],[4],[32]] = 53.7;
ssRidgeCap [[1],[4],[34]] = 56.9;
ssRidgeCap [[1],[4],[36]] = 60.1;
ssRidgeCap [[1],[4],[38]] = 63.3;
ssRidgeCap [[1],[4],[40]] = 66.5;
//Wholesale, galvalume
ssRidgeCap [[2],[1],[14]] = 19;
ssRidgeCap [[2],[1],[16]] = 24.9;
ssRidgeCap [[2],[1],[18]] = 27.7;
ssRidgeCap [[2],[1],[20]] = 30.5;
ssRidgeCap [[2],[1],[22]] = 33.3;
ssRidgeCap [[2],[1],[24]] = 36.1;
ssRidgeCap [[2],[1],[26]] = 38.9;
ssRidgeCap [[2],[1],[28]] = 41.7;
ssRidgeCap [[2],[1],[30]] = 44.5;
ssRidgeCap [[2],[1],[32]] = 47.3;
ssRidgeCap [[2],[1],[34]] = 50.1;
ssRidgeCap [[2],[1],[36]] = 52.9;
ssRidgeCap [[2],[1],[38]] = 55.7;
ssRidgeCap [[2],[1],[40]] = 58.5;
//Wholesale, Kynar
ssRidgeCap [[2],[2],[14]] = 22.48;
ssRidgeCap [[2],[2],[16]] = 26.5;
ssRidgeCap [[2],[2],[18]] = 29.5;
ssRidgeCap [[2],[2],[20]] = 32.5;
ssRidgeCap [[2],[2],[22]] = 35.5;
ssRidgeCap [[2],[2],[24]] = 38.5;
ssRidgeCap [[2],[2],[26]] = 41.5;
ssRidgeCap [[2],[2],[28]] = 44.5;
ssRidgeCap [[2],[2],[30]] = 47.5;
ssRidgeCap [[2],[2],[32]] = 50.5;
ssRidgeCap [[2],[2],[34]] = 53.5;
ssRidgeCap [[2],[2],[36]] = 56.5;
ssRidgeCap [[2],[2],[38]] = 59.5;
ssRidgeCap [[2],[2],[40]] = 62.5;
//Wholesale, Meta1llic Copper
    ssRidgeCap [[2],[3],[14]] = 23.15;
ssRidgeCap [[2],[3],[16]] = 30.5;
ssRidgeCap [[2],[3],[18]] = 34;
ssRidgeCap [[2],[3],[20]] = 37.5;
ssRidgeCap [[2],[3],[22]] = 41;
ssRidgeCap [[2],[3],[24]] = 44.5;
ssRidgeCap [[2],[3],[26]] = 48;
ssRidgeCap [[2],[3],[28]] = 51.5;
ssRidgeCap [[2],[3],[30]] = 55;
ssRidgeCap [[2],[3],[32]] = 58.5;
ssRidgeCap [[2],[3],[34]] = 62;
ssRidgeCap [[2],[3],[36]] = 65.5;
ssRidgeCap [[2],[3],[38]] = 69;
ssRidgeCap [[2],[3],[40]] = 72.5;
//Wholesale, Syl-Poly
    ssRidgeCap [[2],[4],[14]] = 19.1;
ssRidgeCap [[2],[4],[16]] = 26.5;
ssRidgeCap [[2],[4],[18]] = 29.5;
ssRidgeCap [[2],[4],[20]] = 32.5;
ssRidgeCap [[2],[4],[22]] = 35.5;
ssRidgeCap [[2],[4],[24]] = 38.5;
ssRidgeCap [[2],[4],[26]] = 41.5;
ssRidgeCap [[2],[4],[28]] = 44.5;
ssRidgeCap [[2],[4],[30]] = 47.5;
ssRidgeCap [[2],[4],[32]] = 50.5;
ssRidgeCap [[2],[4],[34]] = 53.5;
ssRidgeCap [[2],[4],[36]] = 56.5;
ssRidgeCap [[2],[4],[38]] = 59.5;
ssRidgeCap [[2],[4],[40]] = 62.5;    

var ssRidgePrice = ssRidgeCap [[priceLevel],[ssRidgeColorUp],[ssRidgeWidth]];


document.getElementById("ssRidgeTest4").innerHTML=ssRidgePrice;

結果は常に、Wholesale syl-pol というラベルの付いた配列の最後のセットから得られます。幅を変更すると値が変更されますが、価格レベルまたは色を変更すると (配列の最初の 2 [] は何も変更されません。何らかの理由で、これらの値は [2] と [4] に固定されています。

他に参照が必要な場合は、お尋ねください。投稿します。緊急の助けが必要です

(ps. 価格レベルは、1、2、3 というラベルの付いたラジオ ボタンで設定されます。3 つの決定的な変数 "priceLevel"、"ssRidgeColorUp"、および ssRidgeWidth を出力するテストを行うと、それらは常に正しく表示されますが、配列はそれらを拾いませんか?

よろしくお願いいたします。

4

3 に答える 3

1

配列の代わりにオブジェクトを使用する

var ssRidgeCap = {
    pl_0 : {
        rc_1 : {
            rw_14 : 21.75,
            rw_16 : 28.1
        },
        rc_2 : {
            rw_14 : 25.85,
            rw_16 : 31.3
        }
    },
    pl_1 : {
        rc_1 : {
            rw_14 : 20.38,
            rw_16 : 26.5
        },
        rc_2 : {
            rw_14 : 25.2,
            rw_16 : 30.5
        }
    }
}

それで

var ssRidgePrice = ssRidgeCap['pl_' + priceLevel]['rc_' + ssRidgeColorUp]['rw_' + ssRidgeWidth];
于 2013-05-08T13:15:55.597 に答える