JS alert windows are shown infinitely

0

I have several JS files that validate fields, it happens that when the condition is fulfilled they make the alert and then it is again fulfilled and it continues that way until you mark "Avoid this page ..."

How do I solve it?

Example get called with ONBLUR

function obtener() {
var ejemplo= { xvalor: $('#valor').val() }
$.post("unarchivo.php", xvalor , function( respuesta ) {
if(respuesta.a==99999 )
{
        alert("No existe");
        $('#ejemplo').val("");

}
else
{

    $('#a').val(respuesta.a);
    $('#b').val(respuesta.b);
    $('#c').val(respuesta.c)
}   
}, "json" );

I thought that one of the problems was to do the FOCUS to the value and remove it but it persists.

Or maybe that by entering the value wrong and leaving (blur) it puts the empty box and as empty does not exist in the database it gives you an error and makes a loop?

What can I do to only show the value and not persist

HTML:

<script src="funciones/obtener.js"></script>

<tr>
   <td>Cedula: </td>
   <td colspan="3">
   <input type="text" name="ccedula" id="ccedula" onblur="obtenerSancionado()" maxlength="10" size="12"></td>
   </td>
   </tr>

PHP:

the php if it does not get the value, it happens in response that a = 9999 That's why then the first condition is fulfilled

 if ($stmt->num_rows === 0)
    {
    $datos = json_encode(array(
      "a" => '99999'
    ));
    echo $datos;
    }
    
asked by Victor Alvarado 10.03.2017 в 15:51
source

1 answer

1

The solution was to change to the event onchange . Since I do not remember the name of the person who told me (if you remember tell me and modified the answer) chrome was giving problems with that event in its current version.

It happens that leaving the focus of the text box as well as the message that comes out when writing the card wrongly or not writing it, triggers the event onblur , for that reason it was repeated infinitely, it entered there was no data and it showed message to the Accept the cycle was repeated.

    
answered by 23.04.2017 / 01:37
source