Select dependendes in php

Asked

Viewed 32 times

0

I’m inserting information into a form and I need my selects to be dependent. In this case, I have two selects, containing status information and from the selected state, the city information will appear in the other select. How to do?

<div id="info-geo">                  

<form name="novosDados" action="conexao.php" method="POST"> 

    <legend class="titulo" >Adicionar novo registro </legend> <br><br>

    <div class="w3-row-padding">

        <div class="w3-half">
          <label for="name">Estado</label>
          <select class="w3-select" name="estado">
            <option value="" disabled selected>Escolha um estado</option>
            <option value="BR">MG</option>
            <option value="EDE">SP</option>
            <option value="EVR">RJ</option>
          </select>                            
        </div>

        <div class="w3-half">
            <label for="name">Cidade</label>
            <select class="w3-select" name="cidade">

            <option value="" disabled selected>Escolha uma cidade</option>                                       
            <?php 
            if ($estado == 'MG'){ ?>
                <option value="BH">Belo Horizonte</option>
                <option value="Ipatinga">Ipatinga</option>
            <?php
            }
            ?>


            </select>                              
        </div>
        ....
        ....
        ....
        ....
</form>

How to get this $status amount from my first select ?

  • For what you want to do, do you have to select a state to search for the related cities?

  • Take a look at this repository, it simplifies this work https://gist.github.com/ografael/2037135

  • How could I implement ?

  • Give me about 10 minutes!

  • Better, let’s open a chat!! Gets better from chatting

  • For all I care

  • I think Voce has to open, an option will appear while we comment

  • How to open the chat ?

  • I sent you there

  • related https://answall.com/questions/254739/ajuda-com-combo-box-com-ajax/254809#254809

Show 6 more comments
No answers

Browser other questions tagged

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