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 8412675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:44:00+00:00 2026-06-10T00:44:00+00:00

I would like to insert my ajax query result into a textbox. When user

  • 0

I would like to insert my ajax query result into a textbox. When user select the productcode, the unitprice should be displayed in the textbox. and when the quantity is entered, the unitprice must be multiplied with the quantity and displayed in the textbox. once all data is available in textbox the date need to be uploaded into mysql db. Here is my code.

<script type="text/javascript">
function showUP(str) {
    if (str==""){
        document.getElementById("UnitPrice").innerHTML="";
        return;
    }
    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){
            document.getElementById("UnitPrice").innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","getunitprice.php?q="+str,true);
    xmlhttp.send();
}


function multiply(Quantity) {
    var totalPrice = parseFloat(document.getElementById("UnitPrice").innerHTML)*Quantity;
    document.getElementById("TotalPrice").innerHTML = totalPrice;
}
</script>



</script>

<form action="addorderitemform.php" method="post" name="addorderitemform">



                <table width="600px" border="0" cellspacing="1" cellpadding="3">
                    <tr>
                <th width-"18%>OrderID:</th>
                <td width="60%">
                    <select name="OrderID">
                    <option value="SelectCategory">Select a existing order</option>

                        <?php
                        $query = 'SELECT OrderID FROM customerorder';
                        $result = mysql_query ( $query );
                        while ( $row = mysql_fetch_assoc ( $result ) ) 
                        {
                             print "<option value=\"".$row['OrderID']."\">".$row['OrderID']."</option>\r";
                        }
                        ?>
                        </select></td>
                    </tr>


                                        <tr>
                <th width-"18%>Product:</th>
                <td width="60%">
                    <select name="ProductCode" id="ProductCode" onchange="showUP(this.value)">
                    <option value="SelectCategory">Select product</option>


                        <?php
                        $query1 = 'SELECT ProductCode, ProductName FROM Product';
                        $result1 = mysql_query ( $query1 );
                        while ( $row1 = mysql_fetch_assoc ( $result1 ) ) 
                        {
                             print "<option value=\"".$row1['ProductCode']."\">".$row1['ProductName']."</option>\r";
                        }
                        ?>
                        </select></td>
                         <br/>

                        </tr>

                    <tr>
                <th width-"18%>UnitPrice:</th>
                <td width="60%">
                <input type-"text" name="UnitPrice" id="UnitPrice" size="60" />


                </td>
                </tr>

                <tr>
                <th width-"18%>Quantity:</th>
                <td width="60%">
                <input type-"text" name="Quantity" id="Quantity" onblur= "multiply (this.value)" size="60" />


                </td>
                </tr>

                <tr>
                <th width-"18%>TotalPrice:</th>
                <td width="60%">
                <input type-"text" name="TotalPrice" id="TotalPrice" size="60" />


                </td>
                </tr>

</table>

<input type="submit" value="Add OrderItem" />
<input type="reset" value="Reset" />

</p>
</form>

GETUNITPRICE.PHP

<?php
$q=$_GET["q"];

$con = mysql_connect('localhost', 'root', '');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("Order", $con);

$sql="SELECT CostPrice FROM Product WHERE ProductCode = '".$q."'";

$result2 = mysql_query($sql) or die($sql."<br/><br/>".mysql_error());

while($row2 = mysql_fetch_array($result2)) {

  echo "".$row2['CostPrice']."";


}

mysql_close($con);
?> 

And then upload the details in the textbox to mysql database

<?php
$OrderID = (trim($_POST['OrderID']));
$ProductCode= (trim($_POST['ProductCode']));
$UnitPrice = (trim($_POST['UnitPrice']));
$Quantity = (trim($_POST['Quantity']));
$TotalPrice= (trim($_POST['TotalPrice']));

$host = "localhost";
$user = "root";
$password = ""; 
$db = "Order";
if (!$con = mysql_connect ($host, $user, $password))
    {$message = "Server is not available. Please try again later";
    echo "$message";
    die ();
    }
//or die ("Cannot connect to Server.");

mysql_select_db ($db) or  die ("Database Order not available.");


$query = "INSERT INTO `OrderItem` (`OrderID`, `ProductCode`, `UnitPrice`, `Quantity`, `TotalPrice`) VALUES ('$OrderID','$ProductCode', '$UnitPrice', '$Quantity', '$TotalPrice')";
$result = mysql_query($query) or die($query."<br/><br/>".mysql_error());
//or die ("Insert into OrderItem failed.".mysql_error());
 echo "<script> alert ('Your Information Was Successfully Saved')</script>";
 header("Location: managesalesorder.php"); 

    exit();
    mysql_close($con);

?>
  • 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-06-10T00:44:02+00:00Added an answer on June 10, 2026 at 12:44 am

    Change

    document.getElementById("UnitPrice").innerHTML = xmlhttp.responseText;
    

    to

    document.getElementById("UnitPrice").value = xmlhttp.responseText;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know if its possible to insert Ajax polling into the
I would like to insert the output of multiple calculations into my text document:
I would like to insert a new DataGridViewRow into my DataGridView at a specific
link I would like to insert data in mysql db through ajax. I have
In my view, I would like to insert an HTML table detailing a user's
I would like to select streamitem_id from my insert.php and add it to my
I would like to insert a new node into my Tree. I develop with
I would like to insert the current Subversion revision number (as reported by svnversion
I would like to insert dates in an emacs buffer like I do in
I would like to insert notes on the fixes to be done in specific

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.