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

  • Home
  • SEARCH
  • 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 8488869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:40:10+00:00 2026-06-10T21:40:10+00:00

I have my form like this: Product dropdown Quantity text field UnitPrice display TotalPrice

  • 0

I have my form like this:

  • Product dropdown
  • Quantity text field
  • UnitPrice display
  • TotalPrice display

I have created a function to display the unitprice by querying the db when the dropdown is selected. Now i wanted to be able to display the TotalPrice when the quantity is typed in by multiplying the quantity and the UnitPrice. Understand that the below is the way to multiply but how do i apply it in my query. Included my code too.

<script>
function showUP(str)
{
if (str=="")
{
document.getElementById("UP").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("UP").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getunitprice.php?q="+str,true);
xmlhttp.send();
}
function multiply(Quantity)
{
var totalPrice= parseFloat(document.getElementById("UP"))*Quantity;
document.getElementById("TP").innerHTML= totalPrice;
}
</script>


    <table><tr>
    <th width-"18%>Quantity:</th>
    <td width="60%">
        <input type-"text" name="Quantity" value="" onkeyup= "multiply (this.value)" size="60" />
    </td>
    </tr></table>
<p></p><div id="UP"><b>UnitPrice: 0.00 </b></div><p>
<p></p><div id="TP"><b>TotalPrice: 0.00 </b></div><p>

getunitprice.php

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

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

 mysql_select_db("db", $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 "<b>UnitPrice: ".$row2['CostPrice']."";


 }

    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-10T21:40:11+00:00Added an answer on June 10, 2026 at 9:40 pm

    Use onBlur instead of onchange event. You can also use onkeyup event on quantity textbox.

    <script>
    function multiply(qty)
    {
        var totalPrice= parseFloat(document.getElementById("UP").innerHTML)*qty;
        document.getElementById("TP").innerHTML= totalPrice;
    }
    </script>
    
            <tr>
            <th width-"18%>Quantity:</th>
            <td width="60%">
            <input type-"text" name="Quantity" value="" onkeyup= "multiply (this.value)" size="60" />
    
            </td>
            </tr>
    
    <p></p><div><b>UnitPrice: <span id="UP">0.00</span> </b></div><p>
    <p></p><div id="TP"><b>TotalPrice: 0.00 </b></div><p>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have form like this: <div class=satu> <input type='text' size='1' maxlength='1' name='score[1][]' id='score[1][]'> </div>
I have a form like this: <form id=surveyForm method=post action=submit.php> <input type=text id=good value=0
Suppose I have a form like this: Name:<input type=text name=xxx id=name/> Type:<select> <option>xx</option> <option>xx</option>
I have a simple form like this: <form name=serachForm method=post action=/home/search> <input type=text name=searchText
I have 2 related database tables which in simplified form look like this Product(
I have the following form: <label>One</label> Product ID:<input type=text name=productid[] value=> Product Quantity: <input
I have an html form that looks something like this: <div class=field> <input id=product_name
I have a form like this: <form id='myForm'> <input type='text' name='search' /> <input type='text'
I have form like this : <div id='add_field' class='locbutton'><a href='#' title='Add'>Add</a></div> <div id='remove_field' class='locbutton2'><a
I have form like this: <form method=POST action=<?php echo base_url() ?>admin/admin_search> <fieldset> <label for=nalozi>Nalozi</label><input

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.