私は自分が望む数の著者を追加できる動的フォームを作成しました。関数add_author()insertBeforeがフォームで機能しなくなるdivを追加すると
<form action="uploadtodb.php" target="dummyframe" method="post" name="myform">
<p>
Authors last name: <input type="text" name="authorln[]" size="32" />
Authors first names: <input type="text" name="authorfns[]" size="32" />
</p>
<p id="add_author_button">
<button type="button" onclick="add_author()">Add new author</button>
<button type="button" onclick="remove_author()">Remove last author</button>
</p>
</form>
それは完璧に動作しますが、その後、私はそれにいくつかのスタイルを追加したいパラ
document.myform.insertBefore(para, document.getElementById("add_author_button"));
として以下に示さあるmyForm新しい段落を追加します。だからdivを追加しました:
<form action="uploadtodb.php" target="dummyframe" method="post" name="myform">
<div id="authors">
<p>
Authors last name: <input type="text" name="authorln[]" size="32" />
Authors first names: <input type="text" name="authorfns[]" size="32" />
</p>
<p id="add_author_button">
<button type="button" onclick="add_author()">Add new author</button>
<button type="button" onclick="remove_author()">Remove last author</button>
</p>
</div>
</form>
このような変更ボタンを押しても反応しません。
クラスまたはIDを追加してフォームのスタイルを変更してみませんか?フォームをコンテナとして扱うことができます – Erick
@Erick私はフォームを別のスタイルに分割することに決めました。質問のために私はちょうど著者を抽出した。 –
'para'はもはや' myform'の子ではないので、 'document.myform.insertBefore'はもはや期待どおりに機能していないかもしれません。 – RJM