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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:40:53+00:00 2026-05-20T11:40:53+00:00

The script below computes the subtotal and total of given items. <script type=text/javascript> $(function(){

  • 0

The script below computes the subtotal and total of given items.

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





  $('input[type=button]').click(function(){



});  


$('input[id^=qty]').keyup(function(){
var gtotal=0;
    var parentDiv = $(this).closest('#korokor');
    var curprice=parentDiv.find('input[id^=price]').val();
    var curqty= this.value;
    var curtotal=curprice * curqty;




    parentDiv.find('input[id^=subtotal]').val(curtotal);



    $('input[id^=subtotal]').each(function(index) {
    var currentnum= $(this).val();
    var intnum =parseInt(currentnum);
    gtotal=gtotal + intnum;



  });

  $('input[name=supertotal]').val(gtotal);  
     $('input[name=payment]').val(gtotal);  

});
});
</script>
<?php    
    $viewcarter=mysql_query("SELECT * FROM prod_table WHERE CURRP=1");
?>   



</head>
<body>
<table border="1">
    <tr>
    <th>ID</th>
    <th>PRODUCT</th>
    <th>QA</th>
    <th>PRICE</th>
    <th>QTY BUY</th>
    <th>SUBTOTAL</th>
    <th>REMOVE</th>
    </tr>
</table>
<?php
if(mysql_num_rows($viewcarter)==0){
    //no products

}else{
while($row=mysql_fetch_assoc($viewcarter)){

?>

<form name="blabber" method="get" action="expander.php">
<div id="korokor">
<table border="1">


<tr>
    <td><?php echo $row['PID']; ?></td>
                <td><?php echo $row['PRODUCT']; ?></td>
                <td><?php echo $row['QTYHAND']; ?></td>
                <td><?php echo $row['S_PRICE']; ?></td>

                <input type="hidden" id="pids" name="ids[]" value="<?php echo $row['PID']; ?>">
                <input type="hidden" id="pname" name="product[]" value="<?php echo $row['PRODUCT']; ?>">
                <input type="hidden" name="dprice[]" value="<?php echo $row['B_PRICE']; ?>">
                <input type="hidden" name="sprice[]" id="<?php echo 'price'.$row['PID']; ?>" value="<?php  echo $row['S_PRICE'];  ?>"/>
                <input type="hidden" name="qoh[]"  value="<?php echo $row['QTYHAND']; ?>"/>

                <td><input type="text" name="qbuys[]" id="<?php echo 'qty'.$row['PID']; ?>"/></td>
                <td><input type="text" name="subtotal[]" id="<?php echo 'subtotal'.$row['PID']; ?>"/></td>
                <td><a href="pagmasdan.php?action=2&id=<?php echo $row['PID']; ?>"><img src="delete-icon.png"></img></a></td>
</tr>




</table>
</div>

<?php
}
?>

Grand Total:<input type="text" name="supertotal" value=""/><br/>
Customer:<input type="text" name="customer" value=""/><br/>
Payment:<input type="text" name="payment" value=""/><br/>
<input type="submit" value="sell"/>
</form>
<?php
}

?>

It works, but I have a little problem with its appearance:

enter image description here

I tried to place them all in one table to make it more pleasing but the script which computes the values at keyup no longer works. I need a little help in modifying the appearance of the interface.

  • 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-20T11:40:54+00:00Added an answer on May 20, 2026 at 11:40 am

    Use a single table…

    <form name="blabber" method="get" action="expander.php">
    <div id="korokor">
    <table border="1">
        <tr>
        <th>ID</th>
        <th>PRODUCT</th>
        <th>QA</th>
        <th>PRICE</th>
        <th>QTY BUY</th>
        <th>SUBTOTAL</th>
        <th>REMOVE</th>
        </tr>
    
    <?php
    if(mysql_num_rows($viewcarter)==0){
        //no products
    }else{
    while($row=mysql_fetch_assoc($viewcarter)){
    ?>
    //now the loop adds a new row rather than new table for each item in the cart.
    <tr class="cartItem">
        <td><?php echo $row['PID']; ?></td>
        <td><?php echo $row['PRODUCT']; ?></td>
        <td class="qnty"><?php echo $row['QTYHAND']; ?></td>
        <td class="unitPrice"><?php echo $row['S_PRICE']; ?></td>
        <td><input type="text" name="qbuys[]" id="<?php echo 'qty'.$row['PID']; ?>"/></td>
        <td><input type="text" name="subtotal[]" id="<?php echo 'subtotal'.$row['PID']; ?>"/></td>
        <td><a href="pagmasdan.php?action=2&id=<?php echo $row['PID']; ?>"><img src="delete-icon.png"></img></a>
            <input type="hidden" id="pids" name="ids[]" value="<?php echo $row['PID']; ?>">
            <input type="hidden" id="pname" name="product[]" value="<?php echo $row['PRODUCT']; ?>">
            <input type="hidden" name="dprice[]" value="<?php echo $row['B_PRICE']; ?>">
            <input type="hidden" name="sprice[]" id="<?php echo 'price'.$row['PID']; ?>" value="<?php  echo $row['S_PRICE'];  ?>"/>
            <input type="hidden" name="qoh[]"  value="<?php echo $row['QTYHAND']; ?>"/>
        </td>
    </tr>
    
    <?php
    }
    ?>
    </table>
    </div>
    

    That should fix much of the layout, having loads of tables as you were trying to do is just not a good idea. If the javascript is not working with a single table then it should be adapted so that it does.

    I will take a look at that now…

    This is only very rough im afraid (contact lenses dried out all of a sudden).. but

    var runningSub = 0;
    var total = 0;
    $('.cartItem').each(function(){
        var qnty = $('this .qnty').html();
        var unitPrice = $('this .unitPrice').html();
        runningSub + (qnty * unitPrice);
    )};
    // the cart items have been processed so..
    if(runningSub >0){
        total = (calc for the total price)
    }
    // Now you can set your values..
    

    If you run the above with the additions needed to work out the final total and to put the values onto your page you might have something that works.. or at least a good idea of a direction to go in to get there..

    please look at the HTML for the table as I have amended it to make the javascript simpler to write.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is my current script: <script type=text/javascript> if (navigator.userAgent.indexOf('BlackBerry')!= -1){ document.write('<link rel=stylesheet href=/m/css/mobile.css type=text/css
I'm using this script below for loading a hidden div, inside another: $(document).ready(function(){ $(function()
I am using JQueryUI Dialog and created this function below: <script> $(document).ready(function() { $('#dialog').dialog({
The script below takes the $myContent block and does the doReplace() function on the
I have a jQuery script below that clears the value of an input on
The script below works fine if 3 and 3.2 are not links but i
The script below, test.php, is intended to be placed in a specific directory of
The script below resides in my theme's functions.php file. It is designed to show
The script below worked on my Mac OS X. I'm now using Ubuntu OS,
The script below should open all the files inside the folder 'pruebaba' recursively but

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.