When attaching an event handler to a form element, the scope of the event handler is a form, not a window
<form enctype="multipart/form-data" method="post" onsubmit="return upload(this);"> <script> function upload(scope) { console.log(scope); </script>
Since the input elements inside the form are attached as properties to the form object, where the name is the key, calling upload() in the event handler, where the scope is the form, will be equal to calling form.upload() , but form already has an element with that name, therefore form.upload is a upload button, not a upload() function in the global area.
Rename a function or item to resolve this issue.
<html> <head> <script> function upload(){ alert("I am an alert box!"); } </script> </head> <body> <form enctype="multipart/form-data" method="post" onsubmit="return upload();"> <input type="file" name="file"> <input type="submit" name="upload2" value="Datei hochladen"> </form> </body> </html>
Fiddle
adeneo
source share