如果更改了其他下拉列表,如何更改下拉列表的值?

时间:2015-09-25 09:27:01

标签: javascript arrays drop-down-menu acrobat

好的,编辑:

这些是事实,

我有 4 下拉列表, ddl1,ddl2,ddl3 ddl4

现在我要检查,如果 ddl1 .value是“deutschsprachigeLänder”。 如果是,那么我想用ddl3 填充来自english_opt2 的选项和填充ddl4 english_opt1的选项

ddl2 .value为“englischsprachigeLänder”时,我希望使用来自german_opt2的选项填充ddl3 使用german_opt1 中的选项填充ddl4

如果有可能,我想自动选择旧值/索引(仅使用新语言。)

ddl1 = this.getField("DeutschL");
ddl2 = this.getField("EnglischL");
ddl3 = this.getField("Anrede");
ddl4 = this.getField("Andere Gründe");

english_opt1 =   ["Mögliche andere Gründe auswählen!", 
                 "The recipient is no longer working at that company.",
                 "The recipient is on vacation.", "The recipient is on vacation.",
                 "The receiver is sadly passed away.",
                 "The receiver could not be reached by telephone 3 times.",
                 "The door / access / security code is required.",
                 "The specified address is a flea market.",
                 "The specified address is a Christmas market.",
                 "The specified address is fair.",
                 "The specified telephone number does not belong to the receiver.",
                 "The specified telephone number is not assigned.",
                 "The company is currently closed for summer break.",
                 "The company is currently closed for winter break.",
                 "The company no longer exists.",
                 "The company / the store has closed for renovation.",
                 "There are school holidays in Brandenburg.",
                 "There are school holidays in Berlin."];

german_opt1 =   ["Mögliche andere Gründe auswählen!", 
                "Der Empfänger arbeitet nicht mehr bei dieser Firma.", 
                "Der Empfänger ist im Urlaub.",
                "Der Empfänger ist leider verstorben.", 
                "Der Empfänger konnte 3x telefonisch nicht erreicht werden.", 
                "Der Tür/ Zugangs/ Sicherheits Code ist erforderlich.", 
                "Die angegebene Adresse ist ein Flohmarkt.",
                "Die angegebene Adresse ist ein Weihnachtsmarkt.", 
                "Die angegebene Adresse ist eine Messe.", 
                "Die angegebene Telefonnummer gehört nicht zum Empfänger.", 
                "Die angegebene Telefonnummer ist nicht vergeben.", 
                "Die Firma befindet sich in der Sommerpause.",
                "Die Firma befindet sich in der Winterpause.",
                "Die Firma existiert nicht mehr.", 
                "Die Firma / das Geschäft hat wegen Umbau geschlossen.", 
                "Es sind Schulferien in Brandenburg.",
                "Es sind Schulferien in Berlin."];

english_opt2 =   ["Anrede auswählen!",
                 "Ladies and Gentleman",
                 "Mr.",
                 "Mrs.", 
                 "Family",
                 "Employee of"];

german_opt2 =   ["Anrede auswählen!", 
                "Damen und Herren", 
                "Herr", 
                "Frau", 
                "Mitarbeiter der Firma", 
                "Familie"];

5 个答案:

答案 0 :(得分:0)

这是最简单,最有效的面向对象方式。

Here is the JSFiddle demo

<强> // CODE

<!DOCTYPE html>
<html>
<head>
<script>
var langs = {
    "eng":["one","two","three"],
    "ger":["eins","zwei","drei"]    
};
document.onreadystatechange = function(){
    if(document.readyState == "interactive"){
        document.getElementById("drop1").addEventListener("change",updateDrop);
    }
}
function updateDrop(e){
    var drop = document.getElementById("drop2");
    while(drop.firstChild){
        drop.removeChild(drop.firstChild);
    }
    for(var i=0; i < langs[e.target.value].length; i++){
        var opt = document.createElement("option");
        opt.value = langs[e.target.value][i];
        opt.innerHTML = langs[e.target.value][i];
        drop.appendChild(opt);
    }       
}
</script>
</head>
<body>
    <select id="drop1">
        <option selected disabled>Choose Language</option>
        <option value="eng">English</option>
        <option value="ger">German</option>
    </select>
    <select id="drop2"></select>
</body>
</html>

答案 1 :(得分:-1)

您可以使用<select name="language" onchange="changeNumbers()">并在Javascript中添加以下代码:

function changeNumbers(lang_val) {
  english_nums = ['one', 'two', 'three'];
  german_nums = ['eins', 'zwei', 'drei'];

  if (lang_val == 'english') {
    arr = english_nums;
  } else if (lang_val == 'german') {
    arr = german_nums;
  }
  var options_html = '';
  for (var i = 0; i < arr.length; i++) {
    options_html = options_html + '<option value=' + arr[i] + '>' + arr[i] + '</option>';
  }
  document.getElementById('numbers_select').innerHTML = options_html;
}

答案 2 :(得分:-1)

<script type="text/javascript">
    $(document).ready(function(){
     var english  = ["one", "two", "three"];
     var german  = ["eins", "zwei", "drei "];

        $('#language').on('change', function() {
            var options = "";
            var type = this.value ; 
          //alert( this.value ); // or $(this).val()
          if(type=="english"){
               english.forEach(function(entry) {
            options = options + "<option>"+entry+"</option>";
        });
          }else if(type=="german"){
             german.forEach(function(entry) {
            options = options + "<option>"+entry+"</option>";
        });
          }else{
            options="";
          }
        $("#sub_language").html(options);
        });
});

</script>

<select id="language">
   <option value="0" selected>select</option>
    <option value="english">english</option>
    <option value="german">german</option>
</select>
<select id="sub_language">

</select>

答案 3 :(得分:-1)

<div id="box"></div>select个标记。

然后,其他标签将通过JavaScript

创建

var lang = ["english", "german"];
var second = [
    ["one", "two", "second"],
    ["eins", "zwei", "drei "]
];

addOptions(lang, "first");
addOptions(second[0], "second");

function addOptions(arr, selectId) {
    var s = document.getElementById(selectId);
    if (!s) {
        s = document.createElement("select");
        var myDiv = document.getElementById("box");
        myDiv.appendChild(s);

        s.id = selectId;
    }
    s.options.length = 0;

    for (var i = 0; i < arr.length; i++) {
        var option = document.createElement('option');
        option.text = arr[i];
        option.value = arr[i];
        s.options[s.options.length] = option;
    }
}


document.getElementById("first").onchange = function () {
    console.log(this.selectedIndex)
    addOptions(second[this.selectedIndex], "second");
};
<div id="box"></div>

答案 4 :(得分:-1)

到目前为止,所有海报都(主动)忽略了问题确实在于如何处理PDF中的问题,这意味着在Acrobat JavaScript中。因此,使用HTML的任何代码示例都可能显示某些点,但不可用。

以下函数根据参数加载语言字符串,并保持当前选择(假设默认为英语):

function langChang(lang)
{
// saving the current selections of fields ddl3 and ddl4
var select3 = this.getField("Anrede").currentValueIndices ;
var select4 = this.getField("Andere Gründe").currentValueIndices ;

// clearing the comboboxes
this.getField("Anrede").clearItems() ;
this.getField("Andere Gründe").clearItems() ;

switch(lang) {
case "en":
// Loading the English language strings
this.getField("Anrede").setItems(english_opt1) ;
this.getField("Andere Gründe").setItems(english_opt2) ;
break ;
case "de":
// Loading the German language strings
this.getField("Anrede").setItems(german_opt1) ;
this.getField("Andere Gründe").setItems(german_opt2) ;
break ;
default:
// We assumed that the English language strings are the default
this.getField("Anrede").setItems(english_opt1) ;
this.getField("Andere Gründe").setItems(english_opt2) ;
}

// restoring the selections
this.getField("Anrede").currentValueIndices = select3 ;
this.getField("Andere Gründe").currentValueIndices = select4 ;

}

然后,您将使用DeutschL或EnglishL字段中的Keystroke事件中的相应参数运行该函数。在这两个字段中,您可以设置“立即提交选定值”选项(在“字段属性”对话框的“选项”选项卡中)。

注意:您可能会尝试不清除组合框;在这种情况下,也可能没有必要保存当前选择。这会使功能变小。但目前的功能更可靠。

注意2:这是有效的,因为字符串数组具有等同的语言元素。