Получить выбранное значение из динамического раскрывающегося списка (параметры, сгенерированные javascript для ID)

Я бы сказал, что iText является наиболее дико используемым

1
задан TheMaster 18 January 2019 в 10:55
поделиться

2 ответа

Вы можете использовать document.querySelector. Используйте document.querySelectorAll, чтобы выбрать все select#selectSubject

console.log( document.querySelector( 'select[id=selectSubject]' ) );
console.log( document.querySelectorAll( 'select[id=selectSubject]' ) );
<div id="selectSubject"></div>

<select id="selectSubject" class="select"></select>
<select id="selectSubject"></select>

0
ответ дан Thum Choon Tat 18 January 2019 в 10:55
поделиться

var select = document.getElementById("selectSubject");
var opt = 'youreemailvalue';
var el = document.createElement("option");
el.textContent = opt;
el.value = opt;
select.appendChild(el);

function SetSelectedValue() {
var e = document.getElementById("selectSubject");
 var selected_value = e.options[e.selectedIndex].value;
 document.getElementById('uploadFile').value = selected_value;
 alert('value set to uploadfile')
}
<select id="selectSubject" onchange="SetSelectedValue();"> 
<option>Choose assigned subject</option>
</select>

 <form>
<input type="hidden" name ="subjectFolder" id="uploadFile">
  <input type="file" name="imageFile">
  <input type="button" value="Upload File" onclick="google.script.run.withSuccessHandler().upload(this.parentNode)">
</form>

Следующий код работает для меня

var e = document.getElementById("selectSubject");
var selected_value= e.options[e.selectedIndex].value;

selected_value get значение, которое выбирает пользователь

Рабочий пример Jsfiddle Здесь https://jsfiddle.net/0yfdc51g/

0
ответ дан ravishankar chavare 18 January 2019 в 10:55
поделиться
Другие вопросы по тегам:

Похожие вопросы: