2017-09-26 2 views
-1

Ich habe zwei Optionsfelder, je nach Auswahl auf der erste, ändert es die Optionen für die Sekunde.Ändern des Wertes einer Option trhough Javascript

Momentan sind die Werte für das zweite Feld numerisch, aber ich möchte, dass sie mit der Textoption identisch sind, da sie in einer E-Mail gesendet wird.

Javascript-Code:

var affiliatesAndCompanies = {}; 
affiliatesAndCompanies['Auto Industry'] = ['Company','Company 1', 'Company 2', 'Company3']; 
affiliatesAndCompanies['Door-to-door Sales'] = ['Company', 'Company 5', 'Company 6', 'Company 7']; 
affiliatesAndCompanies['Independent'] = ['Company', 'Company 9', 'Company 10']; 
affiliatesAndCompanies['Mortgage Officer'] = ['Company', 'Company 12', 'Company 13']; 
affiliatesAndCompanies['Real Estate Agent'] = ['Company', 'Company 15', 'Company 16']; 
affiliatesAndCompanies['Seminar Servicers'] = ['Company', 'Company 18', 'Company 19']; 

function ChangeaffiliationList() { 
    var affiliatesList = document.getElementById("affiliation"); 
    var companiesList = document.getElementById("companies"); 
    var selAffiliation = affiliatesList.options[affiliatesList.selectedIndex].value; 

    while (companiesList.options.length) { 
     companiesList.remove(0); 
    } 

    var affiliates = affiliatesAndCompanies[selAffiliation]; 
    if (affiliates) { 
     var i; 
     for (i = 0; i < affiliates.length; i++) { 
      var affiliate = new Option(affiliates[i], i); 
      companiesList.options.add(affiliate); 
     } 
    } 
} 

HTML-Code:

<select class="validate-required" name="parent-affiliate" id="affiliation" onchange="ChangeaffiliationList()"> 
    <option selected="selected" value="">Area of affiliation</option> 
    <option value="Auto Industry">Auto Industry</option> 
    <option value="Door-to-door Sales">Door-to-door Sales</option> 
    <option value="Independent">Independent</option> 
    <option value="Mortgage Officer">Mortgage Officer</option> 
    <option value="Real Estate Agent">Real Estate Agent</option> 
    <option value="Seminar Servicers">Seminar Servicers</option> 
</select> 
</div> 
<div class="select-option col-md-6 p0"> <i class="ti-angle-down"></i> 
    <select class="validate-required" name="parent-affiliate-options" id="companies"> 
    <option selected="selected" value="no-selection">Company</option> 
    </select> 
</div> 

Vielen Dank im Voraus.

Antwort

Verwandte Themen