0

How to click an input with the type submit when a button was clicked?

    $(document).on('click', 'button.editManufacturer', function(event) { 
        event.preventDefault(); 
        $(".editManufacturerSubmit").click();
    });

The snippet above is the code i have so far, but it doesn't work?

Thank you!

===== EDIT =====

Let me explain my problem a little bit more exactly!

I've a lot of forms that i want to submit via only one button.

The following things I have tried before:

    $("button.editManufacturer").click( function() {
        $('form.editManufacturer').submit();
    });

=========================================================================

"form" attribute at the button / input

=========================================================================

and some other things, were i havent the snippets anymore

=========================================================================

NOTE: only the last form is getting submitted

4 Answers4

0

You can Try this

$('button.editManufacturer').on('click', function(event) { 

    $(".editManufacturerSubmit").trigger("click");
});

I am Hopeful it will work for you.

0

Your code seems to work as it is, you may have to provide more code which replicates the problem.

$(document).on('click', 'button.editManufacturer', function(event) { 
  event.preventDefault(); 
  $(".editManufacturerSubmit").click();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="https://httpbin.org/post" method="post">
  <button class="editManufacturer" >button</button>
  <input type="submit" class="editManufacturerSubmit" value="get" onClick="alert('hi')"/>
</form>
Theodore K.
  • 5,058
  • 4
  • 30
  • 46
0

Try this

$(document).ready(function() {
$("form").submit(function(event) { 
   event.preventDefault(); 
});

});

Sujeesh Balan
  • 226
  • 2
  • 3
0

I think what you need is this

$('.editManufacturer').click(function(){
  $('form').submit();
});
soulivong
  • 139
  • 1
  • 3
  • 10
  • i've tried this before! let me explain - i have many forms on one page, and i want them to submit via one button. but nothing works? i also tried to add the "form" attribute to the input / button and tried a lot of js variations, but nothing seems to work :( – Tobi Ratzberger Mar 23 '17 at 09:53
  • you mean one button for all forms? if so why don't you put it in one form? – soulivong Mar 23 '17 at 09:57
  • beacause the forms are saving / updating different documents to one collection in mongodb :/ – Tobi Ratzberger Mar 23 '17 at 10:00