Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function novo_campo_woocommerce( $checkout ) {
- echo '<select id="estados" class="form-control" name="estados">
- <option selected disabled>Escolha seu estado</option>';
- $conexao = new PDO('mysql:host=localhost;dbname=teste', 'user', 'password');
- $sql = ('SELECT * FROM tb_estado ORDER BY nome ASC');
- $sql = $conexao->prepare($sql);
- $sql->execute();
- $lista = $sql->fetchAll();
- for ($i=0; $i < count($lista); $i++) {
- $uf = $lista[$i]['uf'];
- $nome = $lista[$i]['nome'];
- echo "<option value='$uf'>$nome</option>";
- }
- echo '</select>';
- echo '<select class="form-control" name="cidades" id="cidades" required>
- <option value="" selected disabled>Selecione o estado primeiro</option>
- </select>';
- echo '<select class="form-control" name="universidades" id="universidades" required>
- <option value="" selected disabled>Selecione a cidade primeiro</option>
- </select>';
- ?>
- <script>
- $(function(){
- $("#estados").change(function(){
- var uf = $(this).val();
- $.ajax({
- type: "POST",
- url: "func/exibe_cidade.php?uf="+uf,
- dataType:"text",
- success: function(res){
- $("#cidades").children(".cidades").remove();
- $("#universidades").children(".universidades").remove();
- $("#cidades").append(res);
- console.log(res);
- }
- });
- });
- $("#cidades").change(function(){
- var id = $(this).val();
- $.ajax({
- type: "POST",
- url: "func/exibe_universidade.php?id="+id,
- dataType:"text",
- success: function(res){
- $("#universidades").children(".universidades").remove();
- $("#palestras").children(".palestras").remove();
- }
- });
- });
- });
- </script>
- <?php
- }
- <?php
- require_once "conn.php";
- $uf = $_GET['uf'];
- $sql = 'SELECT * FROM tb_cidade WHERE uf = ? ORDER BY nome';
- $stm = $conexao->prepare($sql);
- $stm->bindValue(1, $uf);
- $stm->execute();
- $lista = $stm->fetchAll();
- for($i=0;$i<count($lista);$i++){
- $id = $lista[$i]['id'];
- $nome = $lista[$i]['nome'];
- echo '<option value="'.$id.'" class="cidades">'.$nome.'</option>';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement