javascript - Value from comma separated select option values and append the second value to a other select option -
i'm struggling question, how can value comma separated select option value , append second value other select option? html looks
<select id="firstselecter_id1"> <option value"first value, second value, third value">option1</option> <option value"first value, second value, third value">option2</option> <option value"first value, second value, third value">option3</option> <option value"first value, second value, third value">option4</option> </select> <select id="secondselecter_id2"> <option value"second value">option1-a</option> <option value"second value">option2-a</option> <option value"second value">option3-a</option> <option value"second value">option4-a</option> </select> var entry6 = $('#id_6') entry6.on('change', 'select#firstselecter_id1', function (e) { ... option value ,second .append() #secondselecter_id2 new option value ="" ... }
many if can give me idea , hope have asked question right , understandable regards maty
try
$('#select_1 option').each(function(){ var secondval = this.value.split(',')[1].trim(), $opt = $('<option>').val(secondval).text($(this).text()); $('#select_2').append($opt); });