Sir,
I am using these codes.

<script type="text/javascript">
$("#moba").change(function() {
var formVal = $("#moba").val();
$.get( "ajax_find.php", { id: formVal } ) .done(function( data ) 
{
     $('#my_name').val(data);
     $('#mobb').val(data);
     $('#email').val(data);
});
});
</script>

And ajax_find.php has these codes

<?php
    require_once("connect.php");
    if (isset($_GET['id']))
    {
        $sno =trim($_GET['id']); 
        $record_check ="SELECT * FROM contacts WHERE moba = '$sno' ";
        $result=mysqli_query($con, $record_check);
        $row = mysqli_fetch_array($result); 
        echo (!$row) ? "" : $row['name'];
        echo (!$row) ? "" : $row['mobb'];
        echo (!$row) ? "" : $row['email'];
    }
?>

It shows data as
My_name=Eric00924587582abc@hotmail.com
(3 fields data in FIRST textbox only)

But I want to display data in 3 textbox which has id’s as

$('#my_name').val(data);
$('#mobb').val(data);
$('#email').val(data);

It must display data as

my_name=Eric
mob=00924587582
email= abc@hotmail.com

How to modify both files?

Member Avatar for diafol

If you want to pass data from php to js, then you can use either xml or json. json is easy as jquery ajax has a shortcut method $.getJSON.

The nuts and bolts involved storing the data from php into a keyed array and encoding that as json before echoing, e.g.

echo json_encode(array("my_name"=>$myname,"mobb"=>$mobb,"email"=>$email));

That's all that's required in the php file.

Your jquery...

$.getJSON( "ajax_find.php", { id: formVal } ) .done(function( data ) 
{
     $('#my_name').val(data.my_name);
     $('#mobb').val(data.mobb);
     $('#email').val(data.email);
});

Sir, to understand JSON I wrote some codes and applied your above codes but it does not work, may there is some little mistake. please help again like past

json_dialfol.php

<body>
        <div id="mypopup">
            <div id="header">Search Data</div>
                <div style="margin-top:80px;">
                    <form name="form1" action="" method="post">
                        <table border=0; cellpadding="1" cellspacing="1" bgcolor="#CCFFFF" align="center" >
                            <tr>
                                <td>Code</td>
                                <td width="50px"><input type="text" name="txtsno" id="txtsno" value="" title="Enter product code" /></td>
                            </tr>
                            <tr>
                                <td>Product</td>
                                <td><input type="text" name="txtpro" id="txtpro" value="" title="Enter product name" ></td>
                            </tr>

                                                        <tr>
                                <td>Weight</td>
                                <td><input type="text" name="txtwet" id="txtwet" value="" title="Enter product name" ></td>
                            </tr>


                        </table>
                         <input type="reset" name="button2" value="Clear" >
                    </form>
                </div>
            </div>

<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$("#txtsno").change(function() {
var formVal = $("#txtsno").val();
$.getJSON( "json_dialfol2.php", { id: formVal } ) .done(function( data ) 
{
     $('#txtpro').val(data.packing);
     $('#txtwet').val(data.weight);
});
});
</script>
</body>

json_dialfol2.php

<?php
    require_once("connect.php");
    if (isset($_GET['id']))
    {
        $sno =$_GET['id']; 
        $query ="SELECT * FROM test WHERE sno = '$sno' ";
        $result=mysqli_query($con, $query);
        $row = mysqli_fetch_array($result); 
        echo json_encode(array("txtpro"=>$packing,"txtwet"=>$weight));
    }
?>
Member Avatar for diafol
$row = mysqli_fetch_array($result); 
echo json_encode(array("txtpro"=>$packing,"txtwet"=>$weight));

Where are $packing and $weight set? I'm assuming that you mean:

$row = mysqli_fetch_array($result); 
echo json_encode(array("txtpro"=>$result['packing'],"txtwet"=>$result['weight']));

sir there are only 3 textboxes in form as
txtsno,txtpro,txtwet

I am sending id from txtsno

so this line is not working still

echo json_encode(array("txtpro"=>$result['packing'],"txtwet"=>$result['weight']));

I could not understand what is wrong now?

Member Avatar for diafol

Ok to get to the bottom of this...

$.getJSON( "json_dialfol2.php", { id: formVal } ) .done(function( data ) 
{
     alert(JSON.stringify(data));
});

That'll give you the output of the php file.

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.