How to retrieve All information When I select a value

65 views Asked by At

I have A question in php and jquery When i Select Itemname All information From item name are display on a textbox.. How To do this with jquery?

Here is my codes..

PHP

$iname = $mysqli->prepare("SELECT itemname,quantity,critical_level FROM table_inventory");
    $iname->execute();
    $iname->bind_result($itemname);
    $iname->store_result();

    $itemnames = array();

    while($iname->fetch())
    {
      $itemnames[] = $itemname;
    }


<form>
<div class="form-group ">
<label for="group" class="control-label col-lg-2">Item Name</label>
<div class="col-lg-10">
<select id="quantity"  name="quantity" class="form-control">
<option disabled selected>Item Name</option>
<?php foreach ($itemnames as $i): ?>
<option><?=$i?></option>
<?php endforeach; ?>
</select>

</div>
</div>
<div class="form-group ">
<label for="group" class="control-label col-lg-2">Quantity</label>
<div class="col-lg-10">
<input class=" form-control" required="required" name="group" type="text"  id="output"/>
</div>
</div>
<div class="form-group ">
<label for="group" class="control-label col-lg-2">Critical Level</label>
<div class="col-lg-10">
<input class=" form-control" required="required" name="group" type="text" />
</div>
</div>

</form

when I select from dropdown All the information from i selected are output in the textbox THANKS IN ADVANCE.. SORRY FOR THIS NEWBIE QUESTION

1

There are 1 answers

0
Chitowns24 On BEST ANSWER

Here is a simple example, say you have a bunch of different Makes of cars, and you want it to automatically update with the corresponding models

AJAX CODE that would go in your jQuery Assuming Make is a dropdown and Model is a <textarea id="model"></textarea>

$("#make").change(function(){
    $.ajax({
        url: "http://yoursite.com/modelUpdate.php",
        data: {make: $(make).val()},
        type: "post",
        success: function(msg){
        $("#model").val(msg);
        }
    });
});

So when you change the make in the drop down the value of the make is sent up to modelUpdate.php

Here is some simple PHP code you would need in modelUpdate.php I am not going to write the query out for you but I will show you how to return the data.

$make = $_POST['make']; // This is the AJAX value that was selected on your page
//DO YOUR QUERY HERE TO GET THE DATA
echo $data; 

Anything you echo on this PHP page will be returned and will set that <textarea id="model"></textarea> value.

I hope this gets you started in the right direction