record via input button

Asked

Viewed 369 times

0

Colleagues.

I have through the model of Industrial maintenance in Ajax and thanks to our colleague Dontvotemedown, I can change tabs through the button type, but how would I change tabs, register the information from the previous tab in the bank? The registration in PHP/Mysql I know how to do, what is happening is that when changing tab, there is no input, only if I use the Submit. See below ( I changed the code and is registering in the database, but how do I pass the form values to jquery? ):

     <script>
      $(function() {
        $( "#tabs" ).tabs();
          $("#btnComprar").on("click", function() 
                {
                  $.post("cadastrar_.php", // Cadastando OK
                              {
// Como faço para pegar os valores do formulário e jogar para o campo abaixo?
                             nome: "nome do usuário",
                               idade: "idade"
                  },
                        function(data, status){
                    //   alert("Data: " + data + "\nStatus: " + status);
                        });

                var indice = $('#tabs ul li a[href="#' + $(this).parent().prop("id") + '"]').parent().index();
                    $("#tabs").tabs("option", "active", (indice + 1));

                });
        $(".voltar").on("click", function() 
                {
                    var indice = $('#tabs ul li a[href="#' + $(this).parent().prop("id") + '"]').parent().index();              
                    $("#tabs").tabs("option", "active", (indice - 1));
                });
        });
      </script>

          <button type="button" id="btnComprar" class="proximo btn btn-success pull-right proximo" name="Valor" value="Comprar" style="margin-right: 10px" disabled="disabled"/><i class="fa fa-cart-plus"></i> Comprar </button>
  • You are trying to make a Wizard install form?

1 answer

1


Now there is no mistake, with this example you should be able to solve your problem, but study more JSON, it is worth it and my example is still not the best possible.

html file.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <form>
    <label>Nome
        <input id="nomeId" name="nome" >
    </label>
    <label>Nome novo
        <input id="nomeNovo" name="nomeNovo" >
    </label>
    <button type="button" id="enviar">Vai</button>
  </form>
    <div id="view"></div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script>
  $("#enviar").click(function(){
      var inputNome = $("#nomeId").val();

    $.ajax({
      type:"POST",
      url:"cadastrar.php",
      data:{"nome": inputNome},
      success:function(dados){
        var resposta = $.parseJSON(dados);
        $("#nomeNovo").val(resposta.nome+" Sobrenome");
      }
    });
  });
    </script>
</body>
</html>

php.

<?php
if($_SERVER['REQUEST_METHOD'] != "POST") {exit;}

echo json_encode($_POST);
?>
  • Hello CESD. I tested your code, but unfortunately it didn’t work. I swapped Function(data) for Function(data) and even put it before var Indice = $('#tabs ul li a[href="#' + $(this).Parent().prop("id") + '"]'). Parent(). index(); $("#tabs"). tabs("option", "active", (Indice + 1);.... but it also didn’t work...

  • Also post your HTML if you can...maybe it will be easier to find the error.

  • Actually, I was able to settle on registering in the database based on your response. Now I would like to know how to take the values of the form fields and send to jquery. I edited my question and posted my doubt there.

  • Do a...echo test in php to print the data you entered into the database, then change your return function to see what appears, ideally you would return the php data in the JSON format and distribute to your fields with for example $("#name"). val(name) http://labs.jonsuh.com/jquery-ajax-php-json/ Function(date){ Alert( "Data Loaded: " + date ); });

  • Right CESD. Jquery unfortunately is not my strong and I could not understand very well the link you gave me. On the other hand I used your example and I can see the registration page, but I can’t pass the form values via jquery. I tried using the $("#name") example. val(date.name), but it did not pass and I tried it this way: $("input[name=Name]"). val() and also did not pass. How can I pass the value to the other field to register in the database? The bank registration I can do, but I just need to get the form information and pass via jquery.

  • 1

    I edited my answer, take a look

  • Perfect CESD. It worked. Thank you!

Show 2 more comments

Browser other questions tagged

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