mercredi 20 janvier 2016

Check this with unmarked checkbox if

Hello everyone I have a problem

I am doing an insert with php and ajax with an insert running condition

this is the code:

<input type='checkbox' id="moralibro" name="moralibro" value="mora">  

<script type="text/javascript">  

$(document).ready(function() {  
    $('.error').hide();  
    $(".eliminarp").click(function() {  

        //Obtenemos el valor del campo mora  
        var moralibro = $("input#moralibro").val();  
        //Construimos la variable que se guardará en el data del Ajax para pasar al archivo php que procesará los datos  
            var parent = $(this).parent().attr('id');  
        var service = $(this).parent().attr('data');  
        var dataString = 'id='+service + '&moralibro=' + moralibro ;  
        $.ajax({  
            type: "POST",  
            url: "eliminarprestamo.php",  
            data: dataString,  
            success: function() {              
                $('#delete-ok').empty();  
                $('#delete-ok').append('<div class="correcto">El prestamo se a eliminado correctamente a id='+service+'.</div>').fadeIn("slow");  
                $('#'+parent).fadeOut("slow");  
                //$('#'+parent).remove();  
            }  
        });  
    $('#categoria-registrar')[0].reset();  


        return false;  
    });  
});  


</script>  

This is the file where does the insert eliminarprestamo.php

if (isset($_POST['moralibro']))  
{  
 $query = "INSERT INTO multas_estudiante(cedula_estudiante)   
  VALUES ('12345')";  
  $result = pg_query($query) or die('ERROR AL INSERTAR DATOS: ' . pg_last_error());  
}  

I have tried if (isset ($ _ POST ['moralibro'])) but still makes the insertion unchecked the checkbox, also with if ($ _ POST ['moralibro']! = "")

No more putting it, is affected in some Ajax?

I appreciate your answers




Aucun commentaire:

Enregistrer un commentaire