Jack L
Jack L

Reputation: 19

Javascript/jQuery auto submit form

Working on a 3rd party js script for Slate and need to switch the line form.on('submit', function() to have the submit button fire automatically. I don't need user clicking on submit button. It looks like form.on('submit', function() is a mouse click event to click the submit button? I need to integrate the below with $('#myForm').submit(); somehow I suspect. Can you integrate FW.Lazy.Commit(this, { cmd: 'submit' }); in $('#myForm').submit(); to achieve the functionality?

This works for manual submit:

<script async="async">  /*<![CDATA[*/
    $( document ).ready(function() {
              var form = $('#myForm');
              form.on('submit', function() 
                  FW.Lazy.Commit(this, { 
                  cmd: 'submit' 
                  }); 
              ); 
    })(FW.$);
        /*]]>*/
    </script>

Submit HTML

<form id="myForm"...>
 <button class="default form_button_submit" id="mySubmit" type="button">Submit</button>
</form>

This didn't work for me

 <script async="async">  /*<![CDATA[*/
    $( document ).ready(function() {
            
            $('#myForm').submit(function() 

             FW.Lazy.Commit(this, 
                   { 
                    cmd: 'submit' 
                   } ); 
             );

    })(FW.$);
        /*]]>*/
    </script>

Upvotes: 0

Views: 573

Answers (1)

Hamid Raza
Hamid Raza

Reputation: 32

You can try this:

$("#form-id...").submit(); // in which event you submit this

OR:

$("#form-button").trigger('click'); // the form is automatically submit

Upvotes: 0

Related Questions