There wasn't much wrong with the code except that you are not allowed to have strings spanning over multiple lines in the source code. If you want to do that you would need to break them up and concatenate them again afterwards.
Code:
<div id="text"></div>
<script type="text/javascript">
var fields = 0;
function addInput()
{
var text = document.getElementById('text');
if (fields++ < 5) {
text.innerHTML += '<br />Name: <input type="text" name="name" /><br />Email: <input type="text" name="email" /><br />';
} else {
text.innerHTML += '<br />Only five participants allowed. Thank you.';
document.form.add.disabled = true;
}
}
addInput();
addInput();
addInput();
addInput();
addInput();
addInput();
addInput();
addInput();
</script>
Thanks alot bionoid. Now it works fine. One more question; I want to have those inputs inside <tr> and <td> tags, but the code seems to ignore them. When I look ad the browser's source code, they are not applied. Is there a way I could do this? This is my shot, but doesn't work.
Bookmarks