1

したがって、以下のJavaScriptコードは、自動マーケティングソフトウェアEloquaからデータを取得するために使用しているものです。これは、単一選択のドロップダウンで機能します。私がやりたいのは、複数選択のドロップダウンの作業です。

ProductValue変数が機能することを知っています。つまり、これはドロップダウンで値を呼び出しているため、if(ProductValue == ProductList [i] .value)、具体的には「.value」に含まれていることを確信しています。これを複数にする方法はありますか?これは何日も私を狂わせてきました。

function CustomerInformation()

{

var ProductValue = "<span class=eloquaemail>MarketingCustomerInformation1</span>"; //Field Merge...Field merge is working
var ProductList = document.getElementById('C_Marketing_Customer_Information1').options; //Calling the contact record field

for(var i=0; i< ProductList.length; i++) 
    {       
        if(ProductValue == ProductList[i].value) 
            {
                document.getElementById('C_Marketing_Customer_Information1').value = ProductValue;
                break;
            }
        else 
            {
                document.getElementById('C_Marketing_Customer_Information1').value = "Select";
            }
    }   
}
4

1 に答える 1

0

複数の for ループを使用できます。

var ProductValue = "<span class=eloquaemail>MarketingCustomerInformation1</span>"; //Field Merge...Field merge is working
var ProductList = document.getElementById('C_Marketing_Customer_Information1').options; //Calling the contact record field

for(var i=0; i< ProductList.length; i++) 
{      
    for(var j=0;j<ProductValue.length;j++)
    {
        if(ProductValue[j] == ProductList[i].value) 
        {
          document.getElementById('C_Marketing_Customer_Information1').option[i].selected="selected";
        }
    }
}

ブール変数を追加して、何も選択されていない場合のデフォルトを選択することもできます。

基本的な考え方

  • 最初のループは、複数選択リストのすべての値を処理します。
  • 2 番目のループでは、渡されたすべての値が処理されます (つまり、ProductValue は、選択するすべての値の配列である必要があります)。
  • 最初の配列 (ProductList[i]) の現在のアイテムが 2 番目の配列 (ProductValue[j]) の現在のアイテムと等しい (==) 場合、そのオプションを選択済みとしてマークします。

JS のニーズに役立ついくつかのツール:

  • グーグル
  • W3Schools.com
  • Firebug (Firefox アドオン。ほとんどのブラウザには F12 に関連付けられているものがあり、それを使用して変数を確認し、関数をステップスルーします)
于 2013-02-20T23:07:24.850 に答える