2 action on a Ubmit button?

Asked

Viewed 234 times

2

I’m putting together a form where I send the data to my database, only what kind of form I wanted to run 2 actions on a button submit only that in the case actions sane 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 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 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;
   });

The top one, continues in the same form, like a second part of the form after sending the first..

  • just create a function (function) and call the two actions.

  • Sorry Virgilio, I tried in many ways could help me with the code?

  • What is the sequence of execution

  • First sends ajax_form after step2Button

1 answer

1


By the comments it would be, basically it would 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 it will happen, first it is executed ajax_form and the successful execution of the step2Button.

  • Thank you, it worked out already!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.