Jared Pérez
Jared Pérez

Reputation: 43

Why cant I access input "values" with Jquery?

crear_acta.php

<body>
        <input type="date" name="quantity" maxlength="10" id="create_date">
        <input type="button" value="Siguiente" id="submit_date">
        </p>
</body>

animation.js"

$(document).ready(function() {
    var aux = ""; 
    var paux = "";

    $("#submit_date").click(function(event){                   
        aux = $("#create_date").val();
        paux = $("#create_date").val();        

        // Get date creation and store in DB
        $.post("store_date.php",
        {
           fecha:aux
        },
         function(data,status){
           //alert("Data: " + data + "\nStatus: " + status);
        });

        $('#content').empty();
        $("#content").load("escritura.php");

        // Here I have the date in "paux" and
        // I want to put it in ["escritura.php"->input:id:fecha_acta->value]  but..
        // This doesnt work and I dont know why..    
        $("#fecha_acta").val(paux);         
    });
});

ecritura.php

<form action="tratamiento.php" method="POST">
    <input name="fecha_acta" id="fecha_acta" type="hidden" value="0" />
    <input id="mi_submit" type="submit" class="submit button" value="Save">
</form>    

Upvotes: 0

Views: 52

Answers (1)

Spokey
Spokey

Reputation: 10994

Because the request is asynchronous your script runs before the elements are loaded in the page.

Use the callback and make the changes there (once the request is complete and the elements are in the DOM)

$("#content").load("escritura.php", function(){
    $("#fecha_acta").val(paux);   
});

Upvotes: 1

Related Questions