store values and display them in another field

Asked

Viewed 40 times

0

people developed this website and in the indenizometro part there is a fade.js where when the user clicks on one of the buttons it takes him to the next step
inserir a descrição da imagem aqui

when doing this will appear a small form that he will have to enter this information and when clicking next he will take this information and insert it in the next step only that do not know how to do this is possible ? inserir a descrição da imagem aqui

the input information will be displayed in this step below inserir a descrição da imagem aqui

NOTE: it will not be stored in bank is only to display at the same time. need to do this via jQuery or JS

Follow my php and js code:

PHP:

 <div class="box-informations">
                                <p class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
                                    tempor
                                    incididunt ut labore et dolore magna aliqua</p>
                                <h4 class="subtitle">Selecione a causa: <i class="fa fa-question-circle"
                                                                           aria-hidden="true"></i>
                                </h4>
                                <ul class="list-unstyled list-inline indenizometro-list">
                                    <li class="list"><a class="link -morte">Morte</a></li>
                                    <li class="list"><a class="link -invalidez">Invalidez</a></li>
                                </ul>
                            </div>

                            {{--Event morte--}}
                            <div class="box-informations-morte">
                                <h4 class="title">Causa: <span>Morte</span></h4>
                                <p class="subtitle">Insira os dados do paciente</p>
                                <div class="form-group row">
                                    <div class="col-sm-6 col-xs-6">
                                        <input type="text" name="mail" class="form-control" id="mail"
                                               placeholder="DIGITE A IDADE"/>
                                    </div>

                                    <div class="col-sm-6 col-xs-6">
                                        <input type="phone" name="phone" class="form-control" id="phone"
                                               placeholder="SALARIO ATUAL"/>
                                    </div>
                                </div>
                                <a class="btn-next-morte">Próximo</a>
                            </div>

                            <div class="box-protected-morte">
                                <img src="img/info-segurado.png" class="img-responsive img-segurado"/>
                                <p class="subtitle">Valor da indenização</p>
                                <h3 class="price"><span>R$</span>35.000,00</h3>

                                <a href="{!! route('indenizometro') !!}" class="btn-protected-morte">Proteja-se!<br/><span>Avançe para avaliar seu seguro</span></a>
                            </div>
                            {{--End event morte--}}

                            {{--Evend invalidez--}}
                            <div class="box-informations-invalidez">
                                <h4 class="title">Causa: <span>Invalidez</span></h4>
                                <p class="subtitle">Insira os dados do paciente</p>
                                <div class="form-group row">
                                    <div class="col-sm-6 col-xs-6">
                                        <input type="text" name="mail" class="form-control" id="mail"
                                               placeholder="DIGITE A IDADE"/>
                                    </div>

                                    <div class="col-sm-6 col-xs-6">
                                        <input type="phone" name="phone" class="form-control" id="phone"
                                               placeholder="SALARIO ATUAL"/>
                                    </div>
                                </div>
                                <a class="btn-next-invalidez">Próximo</a>
                            </div>

                            <div class="box-protected-invalidez">
                                <img src="img/info-segurado-2.png" class="img-responsive img-segurado"/>
                                <p class="subtitle">Valor da indenização</p>
                                <h3 class="price"><span>R$</span>25.000,00</h3>

                                <a href="{!! route('indenizometro') !!}" class="btn-protected-invalidez">Proteja-se!<br/>
                                    <span>Avançe para avaliar seu seguro</span>
                                </a>
                            </div>
                            {{--End Event invalidez--}}

JS:

$(document).ready(function(){
    $(".box-informations-morte").hide();
    $(".box-protected-morte").hide();
    $(".box-informations-invalidez").hide();
    $(".box-protected-invalidez").hide();

    //morte
    $(".-morte").click(function(){
        $(".box-informations").hide();
        $(".box-informations-morte").fadeToggle('slow');
    });

    $(".btn-next-morte").click(function(){
        $(".box-informations").hide();
        $(".box-informations-morte").hide();
        $(".box-protected-morte").fadeToggle('slow');
    });
    //end morte

    //invalidez
    $(".-invalidez").click(function(){
        $(".box-informations").hide();
        $(".box-informations-invalidez").fadeToggle('slow');
    });

    $(".btn-next-invalidez").click(function(){
        $(".box-informations").hide();
        $(".box-informations-invalidez").hide();
        $(".box-protected-invalidez").fadeToggle('slow');
    });
    //end invalidez

1 answer

1


Opa, you can use Localstorage or Sessionstorage to store this and recover it later. Follow an example

$('.tipo').on('click', function(){
   sessionStorage.setItem('tipo', $(this).attr('data-tipo'));
})
$('.btn').on('click', function(){
    sessionStorage.setItem('nome', $('input[name=nome]').val());
    sessionStorage.setItem('idade', $('input[name=idade]').val())
    $('.result').append('<p>'+sessionStorage.nome +' - '+ sessionStorage.idade +'</p>')
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<input type="text" placeholder="Nome" name="nome">
<input type="text" placeholder="Idade" name="idade">
<a class="tipo" data-tipo="Invalidez">Invalidez</a>
<a class="tipo" data-tipo="Morte">Morte</a>
<button class="btn">VAMOS LÁ</button>
<div class="result"></div>

  • thanks for the answer in case how are 2 inputs as would the code ? a yes and my button is a link with a class and not a <button> as would be that tbm on the call button on JS

  • @Kirito edited the code

  • @Kirito as more fields just follow the same logic,

  • daora only one more question in the case in the first step only has 2 buttons with death other of disability the choice has to be saved tbm in the place Could you show me how would tbm code please ? that are the links it should appear tbm in the last step <li class="list"><a class="link -death">Death</a></li> <li class="list"><a class="link -invalidity">Invalidity</a></li> a yes and the final outcome would have to have a title age example - 33 years for example in case I leave like this will only appear 33

  • @Kirito you want to click on it save too?

  • not friend just that because then will get a validation and will be saved in a database just want to leave dynamic to present to the client no need to save I want it to look like the result of the third image of my post I’m sorry for that is that I am very newcomer to this programming area

  • in your link you put <a class="link-invalidity" date-type="invalidity">Invalidity</a> sessionStorage.setItem('type', $(this). attr('data-type type'))

  • you put it inside the click of the button

  • Nice ai to make his chamadinah on apend would look like so $('. result-death'). append('<p>'+sessionStorage.idade +' | '+ sessionStorage.salario +' | '+ sessionStorage.morte +'</p>')

  • sessionStorage.setItem('death', $(this).attr('death')) my date-type I put the name of death there I only replace where this type screito by certain death ?

  • Okay, if the answer helped you, please dial as solved and give +1 :D

  • helped yes thanks friend even so that keeps giving Undefined haha

  • $('.btn-next-death'). on('click', Function(){ sessionStorage.setItem('age', $('input[name=age]').val(); sessionStorage.setItem('salary', $('input[name=salary]').val(); sessionStorage.setItem('death', $(this).attr('data-type')) $('result-death').append('<p>'+sessionStorage.idade +' | '+ sessionStorage.salario +' | '+ sessionStorage.morte +'</p>') });

  • my code did not work the date-type part did something wrong ?

  • 1

    @Kirito yes, you did wrong, I will update the code

  • @Kirito updated, you need to use exactly as I did above

  • I love you man you’re the best ahahha

  • Friend if I need to add a back button as it would look could help me?

  • 1

    @Kirito Explain better

  • In fact I already got only what kind when I click back and next again the data duplicates the one accessed on my site and right at home you will see the session indenizomrtro click on death and follow the steps when you get to the big gray button you will see a link to return By clicking on it and then clicking on next again you will see that it duplicates the data and then no longer want that when click-if in coltar that field clear this is the link of the site http://medicalseg.com.br/

Show 15 more comments

Browser other questions tagged

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