I have a button that, when clicked, prompts the user for more info dynamically through an onclick
JavaScript function:
<button type="button" id="create" onclick="addFields()">create?</button>
Once new info has been loaded into the page, I want the button to submit the form:
// .js file
function addFields(){
var container = document.getElementById("initialinfo");
var newInfo = document.createElement('div');
newInfo.setAttribute("id", "createDetails");
newInfo.innerHTML += "divs and checkboxes and radios"
container.appendChild(newInfo);
document.getElementById("create").removeAttribute("onclick");
document.getElementById("create").setAttribute('type', 'submit');
}
Unfortunately, when I do this, the form doesn't submit on the next click. Instead, after the onclick
event, the button (which is now of type submit
) submits the form. How do I prevent this behavior?