I'm using DOM to generate a form like this
const my_form = document.createElement("form");
my_form.enctype = "multipart/form-data";
my_form.onsubmit = function(){return false;};
// inputs here
const div_submit = document.createElement("div");
div_submit.className = "form-group";
const submit = document.createElement("input");
submit.type = "submit";
submit.value = "Register";
submit.onclick = function(){my_function(this.form);};
div_submit.appendChild(submit);
my_form.appendChild(div_submit);
but my problem is when I set the onClick
attribute of the submit input. Using this.form
works when I'm writing directly on html, but when I use JS DOM it says that this.form
is not defined. How can I get the data from the other inputs and pass it as a parameter of the onCLick function?
Comments
Post a Comment