It turns out that I'm trying to pass a value of PHP
to Javascript
to validate me if there is already a certain amount of data.
The PHP
script does its job if the data exists returns 1
and if it does not return 0
, the problem is that I do not know how to take that value again in Javascript
.
I leave the code to see if anyone can help me.
HTML:
!DOCTYPE html>
<html lang = "es">
<head>
<meta charset = "UTF-8">
<title>Formulario de registro</title>
<link rel="stylesheet" href="../css/reg.css">
<script src="../js/llenar.js"></script>
<script src="../js/jquery-3.2.1.min.js"></script>
</head>
<body>
<h1>Formulario de registro</h1>
<form method= "post" class = "form-registro">
<h2> Crear capitanes</h2>
<div class ="contenedor-input">
<input type = "number" id = "cedula" name = "cedula" placeholder = "Cedula" class = "input-100" required>
<input type = "text" id = "nombre" name = "nombre" placeholder = "Nombres" class = "input-48" required>
<input type = "text" id = "apellido" name = "apellido" placeholder = "Apellidos" class = "input-48" required>
<input type = "text" id = "user" name = "user" placeholder = "Usuario" class = "input-48" required>
<input type = "text" id = "pwd" name = "pwd" placeholder = "Contraseña" class = "input-48" required>
<select name = "congregacion" id = "cmbCongregacion" class = "input-100" required>
</select>
<input type = "submit" value = " Registrar capitan" class = "btn-enviar" id = "btn-enviar">
</div>
</form>
</body>
</html>
JAVASCRIPT:
window.onload = function(){
var btnEnviar = document.getElementById("btn-enviar");
btnEnviar.onclick = enviarForm;
var cedula = document.getElementById("cedula");
cedula.onblur = repetido;
$.post("../php/llenar1.php",function(data){
$("#cmbCongregacion").html(data);
});
}
function repetido(){
var cedula = document.getElementById("cedula");
var valor;
valor = cedula.value;
$.post("../php/repetido.php", {cedula: valor}, function(data){
$("#cedula").html(data);
alert(html(data));
});
}
PHP SCRIPT RESPONSE: