Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4054696
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:36:30+00:00 2026-05-20T14:36:30+00:00

I have a dropdown list for items. What I want to do is get

  • 0

I have a dropdown list for items. What I want to do is get the item quantity, remaining quantity and dispatched item values which depends on the value in the drop down.

I have this code :

<form method="post" action="restore_stocks.php">
<table>
<tr>
<td>Item Name:</td>
<td><select name="itemname">
<?php
  $item="SELECT item_name FROM stocks";
  $itemresult = @mysql_query($item)or die ("Error in query: $query. " .                                     mysql_error());
  while($row=@mysql_fetch_array($itemresult)){
echo "<OPTION VALUE=".$row['item_name'].">".$row['item_name']."</option>";
}
?>
</select></td></tr>
<tr>
<td>Item Quantity:</td>
<td><?php 
$row = mysql_fetch_object($itemresult);

echo $row->item_quantity; ?></td></tr>
<tr>
<td>Remaining Quantity:</td>
<td><?php echo $row->rem_quantity; ?></td></tr>
<tr>
<td>Stocks Dispatched:</td>
<td><?php echo $row->stocks_dispatched; ?></td></tr>
<tr>
<td>Add Stocks:</td>
<td><input name="addstocks" type="text" size="25" maxlength="25" /></td></tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" id="Submit" value="Restore" /></td>
</tr>
</table>
</form>

I really don’t know how to start the code because i’m new to this approach. If you can help me it’s much appreciated. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T14:36:30+00:00Added an answer on May 20, 2026 at 2:36 pm

    This works: The jist is that the page uses ajax to call a script, which will deliver XML of the values you need, and will then populate those fields accordingly. :

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <script>
    function updateFields(itemname){
        var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
    {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        var xmlDoc=xmlhttp.responseXML;
        var iQdata=xmlDoc.documentElement.getElementsByTagName("ITEMQUANTITY");
        var rQdata=xmlDoc.documentElement.getElementsByTagName("REMAININGQUANTITY");
        var sDdata=xmlDoc.documentElement.getElementsByTagName("STOCKSDISPATCHED");
        var iQ=iQdata[0].firstChild.nodeValue;
        var rQ=rQdata[0].firstChild.nodeValue;
        var sD=sDdata[0].firstChild.nodeValue;
        document.getElementById("itemQuantity").innerHTML=iQ;
        document.getElementById("remainingQuantity").innerHTML=rQ;
        document.getElementById("stocksDispatched").innerHTML=sD;
        }
      }
    xmlhttp.open("GET","quantity_script.php?itemname="+itemname,true);
    xmlhttp.send();
    
    }
    </script>
    
    <form method="post" action="restore_stocks.php">
    <table>
    <tr>
    <td>Item Name:</td>
    <td><select name="itemname" onchange="updateFields(this.value)">
    <?php
      $item="SELECT item_name FROM stocks";
      $itemresult = @mysql_query($item)or die ("Error in query: $query. " .mysql_error());
      while($row=@mysql_fetch_array($itemresult)){
    echo "<OPTION VALUE=".$row['item_name'].">".$row['item_name']."</option>";
    }
    ?>
    </select></td></tr>
    <tr>
    <td>Item Quantity:</td>
    <td><div id="itemQuantity"></div></td></tr>
    <tr>
    <td>Remaining Quantity:</td>
    <td><div id="remainingQuantity"></div></td></tr>
    <tr>
    <td>Stocks Dispatched:</td>
    <td><div id="stocksDispatched"></div></td></tr>
    <tr>
    <td>Add Stocks:</td>
    <td><input name="addstocks" type="text" size="25" maxlength="25" /></td></tr>
    <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" id="Submit" value="Restore" /></td>
    </tr>
    </table>
    </form>
    
    </body>
    </html>
    

    And then you’d also make a script on your site “quantity_script.php” that would be something like the following:

    <?php
    //include your DB connection info
    $itemname=mysql_real_escape_string($_POST["itemname"]);
    $item="SELECT ".$itemname." FROM stocks";
    $itemresult = mysql_query($item);
    $row=mysql_fetch_assoc($itemresult);
    header('Content-type: text/xml');
    echo "<ROOT>";
    echo "<ITEMQUANTITY>".$row["item_quantity"]."</ITEMQUANTITY>";
    echo "<REMAININGQUANTITY>".$row["rem_quantity"]."</REMAININGQUANTITY>";
    echo "<STOCKSDISPATCHED>".$row["stocks_dispatched"]."</STOCKSDISPATCHED>";
    echo "</ROOT>";
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dropdownlist in a page. The values of all the list items
I have a dropdown list that stores name/value pairs. The dropdown appears in each
I have a drop-down list with known values. What I'm trying to do is
Suppose I have a drop-down list like: <select id='list'> <option value='1'>Option A</option> <option value='2'>Option
I have some html that creates a dropdown list. The list has text values
I have a dropdown list, what I would like to do is assign values
I have dropdown list control in one of my application and when I add
So, I have an autocomplete dropdown with a list of townships. Initially I just
Does anyone know how many options a drop down list can have? Is it
I'd like to add a drop-down list to a Windows application. It will have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.