0

I have a project where in I have a form with a file...
How can I submit the form to a controller action without using the submit button just a plain button?

tereško
  • 58,060
  • 25
  • 98
  • 150
Ramppy Dumppy
  • 2,667
  • 7
  • 27
  • 37

3 Answers3

0

You have many options:

  1. Start uploading of file on selection of file event callback.
  2. Start uploading of file on click on a html element
  3. Upload the obvious way
prady00
  • 721
  • 1
  • 6
  • 17
0

You can use jQuery to achieve what you want. Here is the basics taken from here

<form id="target" action="destination.html">
  <input type="text" value="Hello there">
  <input type="submit" value="Go">
</form>
<div id="other">
  Trigger the handler
</div>

In your jQuery:

$( "#other" ).click(function() {
  //Do stuff, then submit
  $( "#target" ).submit();
});
Akira Dawson
  • 1,247
  • 4
  • 21
  • 45
0

Try this (using plain javascript):

<form action="upload_file.php" method="post"
enctype="multipart/form-data" name="myForm">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="button" name="button1" value="Just a Button" onclick="submitForm()">
</form>



<script type="text/javascript">
 function submitForm() {
    document.myForm.submit();
 }
</script>
myusuf
  • 11,810
  • 11
  • 35
  • 50