简体   繁体   中英

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>    

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);   
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM