0
I’ve been trying to do this for a while, but I failed miserably, I’m trying a different method than the ones I saw on the forum so I don’t think I fall for duplicity.
I need to create a second dropdown from the parameters of the first, would be similar to those in which you enter your state and next appears a list with the cities of the same.
I created three files that would do that:
Html/JS In the verificalist() function, I should be able to call something that prints the list in select "listII"
<html>
<head>
<?php require("cabecalho.php"); ?>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<!-- <script src="ajax.js"></script> -->
</head>
<body>
<form name="listas" method="GET" action="real_time.qm.php">
<a>Origem: </a>
<select id="listI" name="ori">
<option value="0"></option>
<?php
include ("Conectcma.php");
$pl = "SELECT DISTINCT origem FROM reg_qm_papel";
$plgo = mysql_query($pl, $conexao);
while($sc_l = mysql_fetch_array($plgo)){
echo '<option>'.$sc_l['origem'].'</option>';
}
?>
</select>
<select id="listII" name="papel">
<!-- Imprimir a lista aqui dps que chamasse inputasse valor na primeira lista -->
</select>
<button class="css_btn_class" type="submit">Cadastrar</button>
</form>
<script>
$(document).ready(function(){
$('#listI').on('change', function(){
$('#listII').html('');
var ori = $(this).val();
$.ajax({
url: 'puxa.php',
data: {
ori: ori
},
type: 'GET',
dataType: 'json',
success: function(data){
$.each(data, function(){
$('#listII').append('<option>'+this.Papel+'</option>');
})
}
})
});
})
}
</script>
</body>
PHP
include ("Conectcma.php");
$ori = $_GET['ori'];
$pl1 = "SELECT Papel FROM reg_qm_papel WHERE origem = '$ori'";
$plgo1 = mysql_query($pl1, $conexao);
while($sc_l1 = mysql_fetch_assoc($plgo1)){
$vetor[] = array_map('utf8_encode', $sc_l1);
}
echo json_encode($vetor);
?>
Edit1: = I inserted the Ajax function inside the index code, but it doesn’t work yet.
And what error is occurring? What problem is occurring?
– Marcelo de Andrade