Keep field data as select

Asked

Viewed 24 times

1

I have the following code:

    // Dentro do arquivo somar.js
    <script>
    function soma(){
    if(document.getElementById('QtdAcomodacaoSingle').options[0].selected == false){
     TextoAcos = (QtdAco == 1)?("passageiro"):("passageiros");           
                 document.getElementById("alterar").innerHTML = QtdAcos + " " + TextoAcos;
    ......
    }
    }
    </script>

    // Página index.php
    <select name="QtdAcomodacaoS" id="QtdAcomodacaoSingle" class="form-control" style="width:130px" onchange="soma()">
    <option value='1'>1</option>
    <option value='2'>2</option>
    <option value='3'>3</option>
    </option>
<div id="alterar" style="text-align: center; ">---</div>

When I select the number of accommodations, the selected number will automatically appear in the change div. So far so good. But I want to keep the information on the form that was registered. With you in all fields, but how would I make this effect of selecting a number appear in the change div, work after bringing these results in php? I tried that way:

<?php if($_SESSION['Ativo'] == false){ ?>
       <div id="alterar" style="text-align: center; ">---</div>
       <?php }else{ 
              echo $visualizarS->QtdPax; 
            } 
       ?>

When I do so, the change div gets stuck inside the Session validation.

1 answer

2


Try it that way:

<div id="alterar" style="text-align: center; ">
    <?php 
    echo ($_SESSION['Ativo'] == false) ? '---' : $visualizarS->QtdPax; 
    ?>
</div>

Browser other questions tagged

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