2016-09-10 8 views
0
function ff_CselRegion_action(element, action) 
{ 
    country = ff_getElementByName('CselCountry'); 
    state = ff_getElementByName('CselState'); 

    var America_NorthArray = new Array('Antigua and Barbuda', 'Canada', 'Greenland', 'USA', 'Mexico'); 
    if (element.value == 'none') { 
     // drop countries 
     while (country.options.length > 0) 
      country.options[country.options.length-1] = null; 
    } else { 
     // get the matching array 
     var selectedArray = eval(element.value+'Array'); 

     // drop supernumerous option 
     while (selectedArray.length < country.options.length-1) 
      country.options[country.options.length-1] = null; 

     // add the new options 
     country.options[0] = new Option('Select Country', 'none', true, true); 
     for (var i = 0; i < selectedArray.length; i++) 
      country.options[i+1] = 
       new Option(selectedArray[i], selectedArray[i]); 
    } // if 

    // drop states 
    while (state.options.length > 0) 
     state.options[state.options.length-1] = null; 
} // ff_CselRegion_action 
function ff_CselCountry_action(element, action) 
{ 
    state = ff_getElementByName('CselState'); 

    var stateArrayAntigua and Barbuda = new Array(
    'Saint George', 'Saint John', 'Saint Mary', 'Saint Paul' 

    var selectedArray = eval('stateArray'+element.value); 


    if (selectedArray == null) { 
     while (state.options.length > 0) 
      state.options[(state.options.length - 1)] = null; 
    } else { 
     // drop supernumerous option 
     while (selectedArray.length < state.options.length-1) 
      state.options[state.options.length-1] = null; 

     // add the new options 
     state.options[0] = new Option('Select State', 'none', true, true); 
     for (var i=0; i < selectedArray.length; i++) 
      state.options[i+1] = new Option(selectedArray[i], selectedArray[i]); 
    } // if 
} //ff_CselCountry_action 

私はそれがスペースを持っており、(var America_NorthArray)で「アンティグア・バーブーダ」を「見る」ことができないので(var stateArrayAntigua and Barbuda)のための解決策を見つけようとしています。私がプログラミングでは新しいので、あなたの答えはできるだけシンプルになるように感謝します。事前にありがとうアンティグアとバミューダ、私はそれを "見る"ことができない、私はスペースのためだと思いますか?

P.S.私はインターネットで検索しましたが、私はそれを解決することはできませんでした。

答えて

0

変数名の中にスペースを入れることはできません。 var stateArrayAntigua_and_Barbudaにしてください。あなたのコードに他の問題がない場合は、あなたはうまく行きます。

これをもっと深く学びたい場合は、thisを読むことができますが、基本的には変数名にラテン文字の数字_$を使用する方がよいでしょう。

PSはライン

var stateArrayAntigua and Barbuda = new Array(
    'Saint George', 'Saint John', 'Saint Mary', 'Saint Paul' 

に、あなたはまた、構文エラーを得た:閉じ括弧がありません。

+0

ありがとうございました。私はそれを前に考えてみましたが、問題は両方ともAntigua_and_Barbudaでなければなりません。これが起こると、ドロップダウンリストにはそのように表示され、私はこれを望まない。アンティグアとバミューダ(アンダースコアなし)として表示したい – GalanopD

+0

@ギャラノップ「どちらもvarはアンティグアとバブーダでなければならない」とはどういう意味ですか?両方ですか? 2つの変数が必要な場合は、2つ(名前は異なる)を作成しますが、空白を含む変数を持つことはできません。 'window [" stateArrayAntigua and Barbuda "] = ...'や 'var myNewObject = {" stateArrayAntigua and Barbuda ":some value}'のような名前のプロパティを持つオブジェクトを作成することができます。 – YakovL

+0

あなたは閉じ括弧にぴったりです。コピー/貼り付けの間違いです。上記のコードはうまくいきます。単なる名前の国になったときにテストされています。しかし、その国にはもっと多くのものがあります...私はそれをうまくいかない方法を知りません! – GalanopD