2 action on a submit button?

2

I am building a form where I send the data to my database, only type in that form wanted to run 2 actions on a submit button only which in the case actions are id="ajax_form" and id="step2Button" .

How can I execute both in my code, ajax sends the form and step2, continues the form a second part?

This is the id="ajax_form"

<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery('#ajax_form').submit(function(){
            var dados = jQuery( this ).serialize();

            jQuery.ajax({
                type: "POST",
                url: "processar.php",
                data: dados,
                success: function( data )
                {
                    alert( data );
                }
            });

            return false;
        });
    });
    </script>

And this is the id="step2Button

$(document).ready(function(){
    location();
    $('#step2Button').click(function(){
           if($('#username').val()==""){
               swal("Error", "Nome de usuario requerido!", "error")
           }
           if($('#senha').val()==""){
               swal("Error", "Senha requerida!", "error")
           }
           else{
               $('#step1').fadeOut(500,function(){
                   $('#step2').fadeIn(500);
               });
           }

           return false;
   });

This top, continues in the same form, type a second part of the form after sending the first ..

    
asked by anonymous 27.08.2017 / 02:38

1 answer

2

For the comments it would basically be this:

<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery('#ajax_form').submit(function()
        {
            var dados = jQuery( this ).serialize();
            jQuery.ajax({
                type: "POST",
                url: "processar.php",
                data: dados,
                success: function( data )
                {
                    alert( data );
                    fs_click_step2();
                }               
            });
          return false;
        });
    });

    $('#step2Button').click(function(){
       fs_click_step2();
    });

    function fs_click_step2()
    {
        if($('#username').val()==""){
           swal("Error", "Nome de usuario requerido!", "error")
        }
        if($('#senha').val()==""){
           swal("Error", "Senha requerida!", "error")
        }
        else{
           $('#step1').fadeOut(500,function(){
               $('#step2').fadeIn(500);
           });
        }
        return false;
    }
</script>

As will happen, first it executes ajax_form and for is it executes step2Button .

    
27.08.2017 / 03:04