0

I want to send selected value of multiple select (one by one) on script.php file using jQuery or ajax. After sending value on script.php file. I want to show script.php file query result on index.php page specific input box. Like an example: If anyone select Item then Item description and rate show on description and rate input box. Here is my code and image

enter image description here

index.php file code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Item Description</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<script type="text/javascript">
$(document).ready(function() {

    $(".item").change(function() {

    var item = [];
    item:$(".item").each(function() {
            var num = parseFloat(this.value) || 1;
            item.push(num);
    });

        $.ajax({
            type: "POST",
            url: "script.php",
            data: item,
            success: function()
            {
                            // I failed to show script.php value

            }
        });

        return false;
    });

});
</script>
<style type="text/css">
table
{
    border: 1px solid black;
    border-bottom: none;
    width: 600px;
}


td
{
    border-left: 1px solid black;
    border-bottom: 1px solid black;
    padding:5px 5px 5px 5px;
}
#first
{
    border-left: none;
    border-bottom: 1px solid black;
}
</style>
    </head>
    <body>
        <form method='post' name='form1' action='welcome.php'>
        <table cellpadding="0" cellspacing="0">
            <tr>
                <td id="first">Item</td>
                <td>Description</td>
                <td>Rate</td>
            </tr>
            <?php
            $num=4;
            for ($i=0; $i<$num; $i++)
            {
                echo "
             <tr>
                 <td id='first'>
                 <Select class='item' name='item[]'/>
                 <option>Select one</option>
                 <option>Deluxe Plan</option>
                 <option>Premium Plan</option>
                 <option>Standard Plan</option>
                 <option>Economy Plan</option>
                 </select>
                </td>
                <td><textarea class='description' type='text' name='description[]'></textarea></td>
                <td><input class='rate' type='text' name='rate[]'/></td>
               </tr>";
            }
            ?>
     </table>
</form>
</body>
</html>

script.php file code

<?php
include "dbconnect.php";

$item=$_REQUEST['item'];

$query="select * from item where item_name='$item'";
$result=mysql_query or die (mysql_error());

while ($row = mysql_fetch_array($result))
    {
    $description=$row['description'];
    $rate=$row['rate'];
    }
?>

Please, kindly anyone help me to solve this problem.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
user1493448
  • 341
  • 2
  • 5
  • 17
  • `iteam:$(".iteam").each(function() { ` doesn't make any sense - it's probably breaking your script - remove the `iteam:` before the each loop – wirey00 Oct 04 '12 at 20:23

1 Answers1

0

Try this

data: { 'item' : item.serializeArray() }

Serialize the array before you send it your server..

success: function(result) {

}

You use the data parameters from the page and send it to your server... You use the data either to query some result and send back the result in the form of JSON which is light weight.

This return result from the server can be handled in the success callback function of your AJAX request, which can be used to manipulate the DOM...

Check this link: http://www.webdeveloper.com/forum/showthread.php?240091-how-to-return-data-from-php-to-jquery-AJAX

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Sushanth --
  • 55,259
  • 9
  • 66
  • 105