Implement dynamic dependent location select boxes
This commit is contained in:
19
src/ajax.js
Normal file
19
src/ajax.js
Normal file
@@ -0,0 +1,19 @@
|
||||
$(document).ready(function()
|
||||
{
|
||||
$("#provincia").change(function()
|
||||
{
|
||||
var id_provincia = $(this).val();
|
||||
var post_id = 'id='+ id_provincia;
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "../ajax.php",
|
||||
data: post_id,
|
||||
cache: false,
|
||||
success: function(response)
|
||||
{
|
||||
$("#localidad").html(response);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
14
src/ajax.php
Normal file
14
src/ajax.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
include 'database.php';
|
||||
|
||||
if($_POST['id']) {
|
||||
$pdo = connectDatabase();
|
||||
$cities = fetchCities($pdo, $_POST['id']);
|
||||
|
||||
foreach($cities as $row){
|
||||
echo '"<option value="'.$row[0].'">'.$row[4].'</option>';
|
||||
}
|
||||
|
||||
closeDatabase($pdo);
|
||||
}
|
||||
?>
|
||||
@@ -148,4 +148,20 @@ function findPatient($pdo, $input) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
function fetchCities($pdo, $id){
|
||||
$query = "SELECT * FROM municipios WHERE id_provincia=?";
|
||||
$result = $pdo->prepare($query);
|
||||
$result->execute([$id]);
|
||||
$data = $result->fetchAll();
|
||||
return $data;
|
||||
}
|
||||
|
||||
function fetchRegions($pdo){
|
||||
$query = "SELECT * FROM provincias";
|
||||
$result = $pdo->prepare($query);
|
||||
$result->execute();
|
||||
$data = $result->fetchAll();
|
||||
return $data;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -5,8 +5,16 @@
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="../../static/style.css" type="text/css" media="screen" />
|
||||
<script src="../../static/jquery-3.5.1.min.js"></script>
|
||||
<script src="../ajax.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
include '../database.php';
|
||||
|
||||
$pdo = connectDatabase();
|
||||
$regions = fetchRegions($pdo);
|
||||
?>
|
||||
<form method="post" action="../patient_management.php">
|
||||
<div class="input-group">
|
||||
<label>Nombre</label>
|
||||
@@ -36,12 +44,18 @@
|
||||
<input type="text" name="direccion" value="">
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<label>localidad</label>
|
||||
<input type="text" name="localidad" value="">
|
||||
<label>provincia</label>
|
||||
<select id="provincia" name="provincia">
|
||||
<?php foreach($regions as $row) : ?>
|
||||
<option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<label>provincia</label>
|
||||
<input type="text" name="provincia" value="">
|
||||
<label>localidad</label>
|
||||
<select id="localidad" name="localidad">
|
||||
<option>Selecciona la localidad</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<label>pais</label>
|
||||
@@ -51,4 +65,5 @@
|
||||
<button class="btn" type="submit" name="create" >Guardar</button>
|
||||
</div>
|
||||
</form>
|
||||
<?php closeDatabase($pdo); ?>
|
||||
</body>
|
||||
@@ -3,14 +3,14 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||
<title>Gestión de usuarios</title>
|
||||
<title>Gestión de pacientes</title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="../static/style.css" type="text/css" media="screen" />
|
||||
</head>
|
||||
<body>
|
||||
<div style="text-align: right; margin-top: 20px;">
|
||||
<a href="forms/patient_create_form.html" class="create_btn" >Crear</a>
|
||||
<a href="forms/patient_create_form.php" class="create_btn" >Crear</a>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
@@ -21,8 +21,8 @@
|
||||
<th>Documento identificativo</th>
|
||||
<th>Tipo de documento</th>
|
||||
<th>Dirección</th>
|
||||
<th>Localidad</th>
|
||||
<th>Provincia</th>
|
||||
<th>Localidad</th>
|
||||
<th>Pais</th>
|
||||
<th>Citas</th>
|
||||
<th>Informes</th>
|
||||
|
||||
23
src/validate_id.js
Normal file
23
src/validate_id.js
Normal file
@@ -0,0 +1,23 @@
|
||||
function validateDNI(dni) {
|
||||
var number, let, letra;
|
||||
var expresion_regular_dni = /^[XYZ]?\d{5,8}[A-Z]$/;
|
||||
|
||||
dni = dni.toUpperCase();
|
||||
|
||||
if(expresion_regular_dni.test(dni) === true){
|
||||
number = dni.substr(0,dni.length-1);
|
||||
number = number.replace('X', 0);
|
||||
number = number.replace('Y', 1);
|
||||
number = number.replace('Z', 2);
|
||||
let = dni.substr(dni.length-1, 1);
|
||||
number = number % 23;
|
||||
letra = 'TRWAGMYFPDXBNJZSQVHLCKET';
|
||||
letra = letra.substring(number, number+1);
|
||||
if (letra != let) {
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user