以下のプログラムでフォームに入力した値を取得して関数の中でdocument.writeで文字列として表示したいです。値を取得する方法は調べてなんとかなりそうなのですが、どこにそのコードを書けばいいのかわかりません。function zやa,bの中に書くと固まってしまいます。どなたか教えていただけないでしょうか?
追記
フォームの値を取得して表示できるようにはなったのですが、そうするとfunction zが動きません
...
<script> // 削除処理 ``` function deleteInsertTag() {document.close(); var insertTag = document.getElementById("insertTag"); if(insertTag) { insertTag.parentNode.removeChild(insertTag); } } ``` //関数をランダムに実行 ``` function z(){ funcName=["a","b"]; n = Math.floor(Math.random()*funcName.length); eval(funcName[n])(); } ``` ``` function a(){ deleteInsertTag(); // aタグにinsertTagというIDを振っておく document.write('<a id="insertTag" href="#" onclick="z()"><img src="2016-06-18 19.46.54.jpg"/></a>'); document.write("aaa");} ``` ``` function b() { deleteInsertTag(); document.write('<a id="insertTag" href="#" onclick="z()"><img src="2016-06-18 19.46.06.jpg"/></a>');document.write("vvvv");} ``` </script><form name="text"> <input type="text" name="text3" size="20"> <input type="button" name="text2" value="名前" onclick="z()"> </form>
img {width:100%;} </style>``` </body> </html>