Auto Submit javascript

0

I'm having a problem while using the "submit ();" in an input type="file" with an onchage passing an id to the function, I made a test with an alert and it is returning me "[object HTMLFormElement]", I do not know where the problem is.

function autoform(id) {
  alert(id);
  document.getElementById(id).submit();
}
<form action="" id="form" enctype="multipart/form-data">
  <input type="file" onchange="autoform(form);" autocomplete="off">
</form>
    
asked by anonymous 03.06.2018 / 17:36

1 answer

0

The problem with its function is that id is not a string , but an object, which contains the form. You could change your role to:

function autoform(form) {
   alert(form.id);
   document.getElementById(form.id).submit();
}

function autoform(form) {
   alert(form.id);
   document.getElementById(form.id).submit();
}
<form action="" id="form" enctype="multipart/form-data">
  <input type="file" onchange="autoform(form);" autocomplete="off">
</form>
    
03.06.2018 / 17:47