Вопрос

<script type="text/javascript">
    function myfunction() {
        if (document.getElementById('myform').value == "yes") {
            document.getElementById('yesinput').style.display = '';
        } else {
            document.getElementById('yesinput').style.display = 'none';
        }
    }
</script>

<select name="myform" id="myform" onchange="myfunction()">
<option selected="selected">please select</option>
  <option value="yes">Yes</option>
  <option value="no">No</option>
</select>

<div id="yesinput" style="display:none">
<input name="input" type="text" />
</div>

<div id="noinput" style="display:none">
<input name="input" type="text" />
</div>

Помогите вам. Как сделать, если мы выберем Нет будет еще одно поле ввода ниже ID = "noinput".

Теперь это работает, если мы выберем Да. Анкет дай мне знать

Это было полезно?

Решение

function myfunction() {
    if (document.getElementById('myform').selectedIndex == 0) {
        document.getElementById('noinput').style.display = 'none';
        document.getElementById('yesinput').style.display = 'inline';
    } else {
        document.getElementById('noinput').style.display = 'inline';
        document.getElementById('yesinput').style.display = 'none';
    }
}

Другие советы

You can construct a new Element and append it to the DOM via Javascript. An example:

var newInput = document.createElement("input");
newInput.setAttribute("id", "newElement");
newInput.setAttribute("type", "text");
document.body.appendChild(newInput);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top