[英]How do I make radio button hidden until a option is selected in dropdown?
When a option is selected in drop down it shows data from mysql and I need it to be selectable. 当在下拉列表中选择一个选项时,它将显示来自mysql的数据,我需要它是可选的。 So I made a radio button but I need it to appear after option is selected but instead it is always there.
所以我做了一个单选按钮,但我希望它在选择选项后出现,但它始终存在。
Let your radiobuttons div have the id of "radio_div" and your select - "select_options", then: 让您的单选按钮div的ID为“ radio_div”,并选择-“ select_options”,然后:
document.getElementById('select_options').addEventListener('change', function () {
document.getElementById('radio_div').style.display = 'block';
});
Not sure if I understand, but something like this? 不知道我是否理解,但是类似这样的东西?
http://jsfiddle.net/zysrcndx/ http://jsfiddle.net/zysrcndx/
HTML: HTML:
<select id="show">
<option value="no" selected="selected">not showing</option>
<option value="yes">showing</option>
</select>
<div id="radio" style="display: none;">
<input type="radio" name="radio" value="something">Something<br>
<input type="radio" name="radio" value="somethingelse">Something Else
</div>
JavaScript: JavaScript:
var dd = document.getElementById('show');
var r = document.getElementById('radio');
dd.addEventListener('change', function () {
if(dd.options[dd.selectedIndex].value == 'no') {
r.style.display = 'none';
} else {
r.style.display = 'block';
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.