admin管理员组文章数量:1023868
I'm trying to use a drop down next to a simple number input within a section on a dynamic web page form. I am able to create a new section with a button, and I can use normal text or number fields within that section. However when I try and create a drop down within a section I cannot get it to work.
I can get the dropdown to work fine when its independent, just not within the dynamically created section.
document.getElementById('addVegetablesButton').addEventListener('click', function() {
var newSection = document.createElement('fieldset');
var legend = document.createElement('legend');
legend.textContent = 'Vegetable';
var newField1 = document.createElement('input');
newField1.type = 'number';
newField1.name = 'sectionField1';
newField1.placeholder = 'Quantity';
var newField2 = document.createElement('label');
newField2.textContent = 'Vegetable type:';
var newSelect = document.createElement('select');
newSelect.name = 'dynamicSelect';
var option1 = document.createElement('option');
option1.value = 'option1';
option1.textContent = 'Carrot';
var option2 = document.createElement('option');
option2.value = 'option2';
option2.textContent = 'Brussel Sprout';
newSelect.appendChild(option1);
newSelect.appendChild(option2);
newSection.appendChild(legend);
newSection.appendChild(newField1);
newSection.appendChild(newField2);
document.getElementById('dynamicForm').appendChild(newSection);
});
With the above the first element (quantity) works fine, the label for the newField2 shows, but no drop down. I tried various configurations where the button woldn't even generate the section, the above is as close as I have come to it work.
I'm trying to use a drop down next to a simple number input within a section on a dynamic web page form. I am able to create a new section with a button, and I can use normal text or number fields within that section. However when I try and create a drop down within a section I cannot get it to work.
I can get the dropdown to work fine when its independent, just not within the dynamically created section.
document.getElementById('addVegetablesButton').addEventListener('click', function() {
var newSection = document.createElement('fieldset');
var legend = document.createElement('legend');
legend.textContent = 'Vegetable';
var newField1 = document.createElement('input');
newField1.type = 'number';
newField1.name = 'sectionField1';
newField1.placeholder = 'Quantity';
var newField2 = document.createElement('label');
newField2.textContent = 'Vegetable type:';
var newSelect = document.createElement('select');
newSelect.name = 'dynamicSelect';
var option1 = document.createElement('option');
option1.value = 'option1';
option1.textContent = 'Carrot';
var option2 = document.createElement('option');
option2.value = 'option2';
option2.textContent = 'Brussel Sprout';
newSelect.appendChild(option1);
newSelect.appendChild(option2);
newSection.appendChild(legend);
newSection.appendChild(newField1);
newSection.appendChild(newField2);
document.getElementById('dynamicForm').appendChild(newSection);
});
With the above the first element (quantity) works fine, the label for the newField2 shows, but no drop down. I tried various configurations where the button woldn't even generate the section, the above is as close as I have come to it work.
本文标签: htmlNesting a drop down inside a section in a dynamic javascript formStack Overflow
版权声明:本文标题:html - Nesting a drop down inside a section in a dynamic javascript form - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745607673a2158821.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论