Sir I have these codes

<script>
    function myCall() {

        var data = $("#datepicker-13").val();

        alert(data)
        var request = $.ajax({

            url: "ajax_arrival.php",
            type: "Get",
            data: {
                "date": data
            },
            dataType: "html"
        });

        request.done(function(msg) {
            msg = data.split("##");
            $("#wh_bg1").val(msg[0]);
            $("#wh_jt1").val(msg[1]);
            $("#wh_wt1").val(msg[2]);
            //                        alert(msg);
            });

        request.fail(function(jqXHR, textStatus) {
            alert("Request failed: " + textStatus);
        });
    }
</script>

and ajax_arrival.php is like this

$query ="SELECT qty,jute,weight FROM arrival where date= '$date.'";
$result=mysqli_query($con, $query);

if ($result){
$row = mysqli_fetch_array($result); 
$msg=$row['qty']."##".$row['jute']."##".$row['weight'];
echo $msg; 
}

The query gets proper data in $msg but this response section does not work

   request.done(function(msg) {
                msg = data.split("##");
                $("#wh_bg1").val(msg[0]);
                $("#wh_jt1").val(msg[1]);
                $("#wh_wt1").val(msg[2]);
                });

Please help me how to display responsed data into these textboxes

<input type="text" id="wh_jt1" name="wh_jt1" value="<?php if($wh_jt>'0'){ echo $wh_bg;}else{echo "";}?>"/> <input type="text" id="wh_bg1" name="wh_bg1" value="<?php if($wh_bg>'0'){ echo $wh_bg;}else{echo "";}?>" /> <input type="text" id="wh_wt1" name="wh_wt1" value="<?php if($wh_wt>'0'){ echo $wh_wt;}else{echo "";}?>"/>

Thanks

Member Avatar for diafol

Firstly, you do not have to concatenate and split the php output - use json_encode on an array of items. Secondly, js cannot pass data to php within the same page - php is done and only then is js run.

So:

if ($result){
    $row = mysqli_fetch_array($result); 
    $msg = ["qty"=>$row['qty'],"jute"=>$row['jute'],"weight"=>$row['weight']];
    echo json_encode($msg); 
}

Your js then:

request.done(function(msg) {
            $("#wh_bg1").val(msg.qty);
            $("#wh_jt1").val(msg.jute);
            $("#wh_wt1").val(msg.weight);
            });
Member Avatar for diafol

BTW:

$query ="SELECT qty,jute,weight FROM arrival where date= '$date.'";

Looks wrong as it has a period at the end. Also, ensure that you sanitize $date or you will be open to SQL injections. Ideally, you'd use a prepared statement. See my tute:

https://www.daniweb.com/programming/web-development/tutorials/499320/common-issues-with-mysql-and-php - points #2 and #4.

Your html could be this, if you are populating directly from PHP on page load:

<input type="text" id="wh_jt1" name="wh_jt1" value="<?php if($wh_jt>0) echo $wh_bg;?>"/> 
<input type="text" id="wh_bg1" name="wh_bg1" value="<?php if($wh_bg>0) echo $wh_bg;?>" /> 
<input type="text" id="wh_wt1" name="wh_wt1" value="<?php if($wh_wt>0) echo $wh_wt;?>"/>

However your variables seem messed up in the first one - I think it should be echo $wh_jt. Or just this if waiting for a date:

<input type="text" id="wh_jt1" name="wh_jt1" /> 
<input type="text" id="wh_bg1" name="wh_bg1" /> 
<input type="text" id="wh_wt1" name="wh_wt1" />
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.