2009-09-02 20 views
1
<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> 

ヘルプya。 Noを選択すると、id = "noinput"の下に別の入力フィールドが表示されます。Javascript - getElementByIdと助けてください

はいを選択すると、現在動作しています。私に教えてください

+0

私は何をお使いの提示見当がつかない。 – Zoidberg

+0

笑..申し訳ありませんが、私はもっと詳しく説明しようとしています。 (言語がほとんど)多分誰かがコードを実行する必要があります – wow

答えて

4
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'; 
    } 
} 
+0

ありがとうkyle rozendo;) – wow

+1

確かに、それは助けてうれしい;) –

0

新しい要素を作成し、それをJavascript経由でDOMに追加することができます。例:

var newInput = document.createElement("input"); 
newInput.setAttribute("id", "newElement"); 
newInput.setAttribute("type", "text"); 
document.body.appendChild(newInput); 
関連する問題