How to make a call from a file that contains an ajax form?

Asked

Viewed 34 times

0

How I call a file that has the content of the conditions form?

Html

<label>SELECIONE UMA OPÇÃO</label>
     <form>
      <label><input value="A" name="opcao" type="radio">opcao A</label> 
      <label><input value="B" name="opcao" type="radio">opcao B</label>
      <label><input value="C" name="opcao2" type="radio">opcao C</label> 
      <label><input value="D" name="opcao2" type="radio">opcao D</label> 
      <div>
                CONTEUDO DO FORMULARIO AQUI
      </div>

     </form>

Script

$(document).ready(function() {

                    $('input[type="radio"]').change(function(event) {
                        var option1 = $('input[name="opcao"]').filter(':checked').val();
                        var option2 = $('input[name="opcao2"]').filter(':checked').val();
                        getForm(option1, option2)

                    });

                    // Traz o form com ajax
                    function getForm(option1, option2){
                        console.log(option1);
                        console.log(option2);

                        if ( (option1 == 'A') && (option2 == 'C') ) {
                            // Faz uma chamada ajax para trazer o formulario
                        }

                        if ( (option1 === 'A' && option2 === 'D') ) {
                            // Faz uma chamada ajax para trazer o formulario
                        }

                        if ( (option1 === 'B' && option2 === 'C') ) {
                            // Faz uma chamada ajax para trazer o formulario
                        }

                        if ( (option1 === 'B' && option2 === 'D') ) {
                            // Faz uma chamada ajax para trazer o formulario
                        }
                    }

                });

1 answer

0

You can create several <div>s with different forms and display only the ones you want within your script. For example:

HTML

<div id='form1'></div>
<div id='form2'></div>
<div id='form3'></div>

Script

if ( (option1 == 'A') && (option2 == 'C') ) {
    // Faz uma chamada ajax para trazer o formulario
    $('#form1').show();
}    
if ( (option1 === 'A' && option2 === 'D') ) {
    // Faz uma chamada ajax para trazer o formulario
    $('#form2').show();
}
  • So I can call wanted to call a type file. <? php require_once('/config.php'); ?>

  • What exactly do you want to return according to each condition? A specific form for each option, or a p/each configuration file? be more specific...

Browser other questions tagged

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