views:

137

answers:

2
<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>

Help ya. How to make if we select No will have another input field below the id="noinput".

Now it's working if we select Yes. let me know

A: 

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);
marshall_law
+3  A: 
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';
    }
}
Kyle Rozendo
thanks kyle rozendo ;)
bob
Sure thing, glad it helped ;)
Kyle Rozendo