So I have a simple form-extension script:
var counter=1;
function newField(counter) {
counter++;
var newFields = document.getElementById('readroot').cloneNode(true);
newFields.id = "formcheck"+counter;
newFields.style.display = 'block';
var newField = newFields.childNodes;
var insertHere = document.getElementById('writeroot');
insertHere.parentNode.insertBefore(newFields,insertHere);
}
being called inside of a form:
<form id='newanimal' action='/submit' method='post'>
<span id='writeroot'></span>
<button id='newField' type='button' onclick=newField();>Add Field</button>
</form>
readroot looks like this:
<div id="readroot" style="display: none">
<input type="button" value="Remove review"
onclick="this.parentNode.parentNode.removeChild(this.parentNode); counter--;" /><br /><br />
<input id="checkform" name="checkform" value="New Checkform" />
</div>
Now the function works fine, unless it's called from inside of a form. When executed as-is, I get newField is not a function called as an error, however if you remove the form tags and it runs fine.
Any idea what's going on?