简体   繁体   中英

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>

You can try this:

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

OR:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM