I'm new with coding and I found some really valuable information that could help my register form look better using Ajax.
The problem is that, even though the php files are working fine, I think that the js file is not doing it's job. here:
in the register form there's this:

`<?php
 include 'php_includes/conexion.php'; (connect to DB users)
 include 'php_includes/conexionlugar.php'; (connect to DB states/cities)
?>`

```
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/jquery.js"></script>
</head>

```

in the form there's this:

***Select State***

```
<select name="departamento" id="departamento">
<option value="">Seleccione Departamento</option>
<?php echo cargar_departamentos();?>
</select>

```

***Select City***

```
<select name="provincia" id="provincia">
<option value="">Seleccione Provincia</option>
</select>

```

Now, in the conexionlugar.php (tested/working):

`<?php
 function cargar_departamentos()
 {
 $connect = mysqli_connect("localhost", "root", "root", "lugar");
 $output = '';
 $sql = "SELECT * FROM departamentos ORDER BY NOMBRE_DEPA";
 $result = mysqli_query($connect, $sql);
 while($row = mysqli_fetch_array($result))
 {
 $output = '<option value="'.$row["IDDEPARTAMENTOS"].'">'.$row["NOMBRE_DEPA"].'</option>';
 echo "$output";
 }
 }
 return $output;
?>`

in the jquery.js (don't know much about this :()

`$(document).ready(function(){
 $('#departamento').change(function(){
 var IDDEPARTAMENTOS = $(this).val();
 $.ajax({
 url:'../php_includes/fetch_provincia.php',
 type:"POST",
 data:{departamentoId:IDDEPARTAMENTOS},
 dataType:"text",
 success:function(data)
 {
 $('#provincia').html(data);
 }
 });
 });
});`

in the fetch\_provincia.php (tested/working)

`<?php
 $connect = mysqli_connect("localhost", "root", "root", "lugar");
 $output ='';
 $sql = "SELECT * FROM provincias WHERE departamentos_IDDEPARTAMENTOS = '".$_POST["departamentoId"]."' ORDER BY NOMBRE_PROV";
 $result = mysqli_query($connect, $sql);
 $output = '<option value="">Seleccione Provincia</option>';
 while($row = mysqli_fetch_array($result))
 {
 $output = '<option value="'.$row["IDPROVINCIAS"].'">'.$row["NOMBRE_PROV"].'</option>';
 echo $output;
 }
 return $output;
?>`

Though separately the PHP files are working, the JS file changing departamentoId for IDDEPARTAMENTOS looks like it's not... help me please.

**I think I fixed it, deleting the "return" on both php and adding the js to the same page and not calling it through**