Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form id="form">
- <div id="step1" class="step">
- <h1>Paso 1</h1>
- <!-- Diferentes tipos de campo input u otros que se necesitan validar-->
- <a href="#" onclick="show_step('2')">continuar</a>
- </div>
- <div id="step2" class="step">
- <h1>Paso 2</h1>
- <!-- Diferentes tipos de campo input u otros que se necesitan validar-->
- <a href="#" onclick="show_step('1')">Atras</a>
- <a href="#" onclick="show_step('3')">continuar</a>
- </div>
- <div id="step3" class="step">
- <h1>Paso 3</h1>
- <!-- Diferentes tipos de campo input u otros que se necesitan validar-->
- <a href="#" onclick="show_step('2')">Atras</a>
- <a href="#" onclick="show_step('4')">continuar</a>
- </div>
- <div id="step4" class="step">
- <h1>Paso 4</h1>
- <!-- Diferentes tipos de campo input u otros que se necesitan validar-->
- <a href="#" onclick="show_step('3')">Atras</a>
- <input><-- Finalizar
- </div>
- </form>
- function show_step(step){
- var data = $( "#form" ).serialize();
- var url = 'saveTemp.php?step=' + step;
- // recuperamos el lavel del radio button seleccionado
- //var valor_radio = $('input:radio[name=radio]:checked').next("label").text();
- $.ajax({
- type: "POST",
- url: url,
- data: data
- }).done(function(resp){
- step = parseInt(step);
- $('#address').val(resp.address);
- $('#email').val(resp.email);
- $('#name').val(resp.name);
- $('#phone').val(resp.phone);
- $('#radio').val(resp.radio);
- $('#username').val(resp.username);
- if (step === 2) {
- var radio = parseInt(resp.radio);
- switch(radio) {
- case 1:
- urlform = './app/themes/pay_paypal.php'
- break;
- case 2:
- urlform = './app/themes/pay_paypal2.php'
- break;
- case 3:
- urlform = './app/themes/pay_paypal3.php'
- break;
- default:
- urlform = './app/themes/pay_paypal4.php'
- break;
- }
- $('#divPago').load(urlform,function(responseTxt, statusTxt, xhr){
- if(statusTxt === "success") {
- $('.step').css( "display", "none" );
- $('#step'+ step).fadeIn("slow");
- animacion(step);
- }
- if(statusTxt === "error") {
- //
- }
- });
- } else {
- $('.step').css( "display", "none" );
- $('#step'+ step).fadeIn("slow");
- animacion(step);
- }
- });
- };
- $(function() {
- show_step(step);
- });
- $("input").each(function () { //inicia un bucle con todos los inputs
- if ($(this).val() == '') { //Si el input esta "vacio"
- alert("Debe llenar todos los campos");
- return false; //detiene el bucle
- }
- });
- $("input:checkbox") //solo los checkbox
- $("input:radio") //solo los radios
- $("select") // los select
- //tambien puedes comprobar varios tipos a la vez
- $("select, input:text, input:checkbox")
- if (!$(this).is(':checked')) { //Si el checkbox no esta seleccionado
- alert("Debe llenar todos los campos");
- return false; //detiene el bucle
- });
- function show_step(step){
- var data = $( "#form" ).serialize();
- var url = 'saveTemp.php?step=' + step;
- var emptyInput = false;
- $("input").each(function () { //inicia un bucle con todos los inputs
- if ($(this).val() == '') { //Si el input esta "vacio"
- emptyInput = true;
- return false; //detiene el bucle
- }
- });
- if (emptyInput) {
- alert("Todos los campos son obligatorios");
- return void; //Detiene la ejecucion de esta funcion
- }
- // recuperamos el lavel del radio button seleccionado
- //var valor_radio = $('input:radio[name=radio]:checked').next("label").text();
- $.ajax({
- type: "POST",
- url: url,
- data: data
- }).done(function(resp){
- step = parseInt(step);
- $('#address').val(resp.address);
- $('#email').val(resp.email);
- $('#name').val(resp.name);
- $('#phone').val(resp.phone);
- $('#radio').val(resp.radio);
- $('#username').val(resp.username);
- if (step === 2) {
- var radio = parseInt(resp.radio);
- switch(radio) {
- case 1:
- urlform = './app/themes/pay_paypal.php'
- break;
- case 2:
- urlform = './app/themes/pay_paypal2.php'
- break;
- case 3:
- urlform = './app/themes/pay_paypal3.php'
- break;
- default:
- urlform = './app/themes/pay_paypal4.php'
- break;
- }
- $('#divPago').load(urlform,function(responseTxt, statusTxt, xhr){
- if(statusTxt === "success") {
- $('.step').css( "display", "none" );
- $('#step'+ step).fadeIn("slow");
- animacion(step);
- }
- if(statusTxt === "error") {
- //
- }
- });
- } else {
- $('.step').css( "display", "none" );
- $('#step'+ step).fadeIn("slow");
- animacion(step);
- }
- });
- };
Add Comment
Please, Sign In to add comment