Good morning,
The purpose of this code is to check if a record (number), sent through the form, exists in the database. The submit button (which is invisible) must be displayed on screen if it is confirmed that the record entered exists in the database.
It happens that the input submit disappears from the screen only when a record is entered in the input text and then it is deleted.
I do not understand why the conditional of this jQuery code does not apply as I think it should.
The code is divided into 2 files.
File 1 - JAVASCRIPT + HTML:
$(document).ready(function() {
document.seleccionar.modificar.style.visibility = "hidden";
var consulta;
$("#id").focus();
$("#id").keyup(function(e){
consulta = $("#id").val();
$("#resultado").delay(100).queue(function(n) {
$("#resultado").html('<img src="imagenes/loading/ajax-loader.gif" />');
$.ajax({
type: "POST",
url: "comprobar.php",
data: "b="+consulta,
dataType: "html",
error: function(){
alert("Error petición ajax");
},
success: function(data){
$("#resultado").html(data);
n();
if (data == 1){
document.seleccionar.modificar.style.visibility = "visible";
}
}
});
});
});
});
-------------------------------------------------------------
<form name="seleccionar" id="seleccionar" action="modificar.php" method="post">
<input type="int" required id="id" name="id" placeholder="Introduce ID..." value="" />
<span id="resultado"></span>
<input type="submit" id="modificar" name="modificar" value="Modificar" /><br><br/>
</form>
File 2 - PHP:
<?php
$user = $_POST['b'];
if(!empty($user)) {
comprobar($user);
}
function comprobar($b) {
include("conexion_db.php");
$query = mysqli_query($conexion, "SELECT * FROM formulario WHERE id = '".$b."'");
$contar = mysqli_num_rows($query);
if($contar == 0){
echo "<span><img src=\"imagenes\web\action_delete.png\"></span>";
}else{
echo "<span><img src=\"imagenes\web\action_check.png\"></span>";
}
echo json_encode($contar);
}
?>
I would appreciate if someone could tell me why the input submit is not displayed when the condition is executed. Thanks in advance.