count usage

That has to be the most overly complicated script, really bloated, but I don’t have time to sit here and write one now. sub = (QTY * Price) needs to be var sub = (QTY * Price);

I’ll write a less complicated version tonight.

i hv tried a var sub but din work out…

[php]

$(function(){
$(‘input’).each(function() {
$(this).keyup(function(){
calculatedis($(this));
});
});
});

      function calculatedis(src) {
      var sub = 0;
      var sumtable = src.closest('.sumtable');
      sumtable.find('tr').each(function() {
          var QTY = parseInt($(this).find('input[name="QTY"]').val());
            var Price = parseInt($(this).find('input[name="Price"]').val());
           var sub = (QTY * Price)
        $(this).find('.amount').val(sub);
          });
      sumtable.find(".amount").val(sub.toFixed(2));
      }   
     </script> </head>
  <form method="post" action="add_trx.php" />
        <table>
        <tr>
  <td><input name="checkbox_id" type="hidden" id="checkbox_id" value="<?php echo

$row[‘id’] ?>" checked = “checked” disabled = “disabled”>


  <tr>
  <td>Customer Name :</td>
  <td><input type="text" name="company_name" size="20" value="<?php echo $row['company_name'] ?>" disabled = "disabled"></td>
  </tr>
  
  <tr>
  <td>Address :</td>
  <td><input type="text" name="company_address" size="20" value="<?php echo $row['company_address'] ?>" disabled = "disabled"></td>
  </tr>
  
<tr>
  <td>Date :</td>
  <td><input type="date" name="invoice_date" size="20"></td>
  </tr>
  </table>
  <center>

  <table cellpadding="3" border accesskey="1">
  <tr>
    <td>Item Description</td>
    <td>Quantity</td>
    <td>Unit Price</td>
    <td>Amount</td>
    </tr>
          <tr>
            <td></td><td></td><td></td>
            <td align="right"><input type="submit"  name="submit" value="submit"></td>
          </tr>
  </table>
  </center>
  </form>
 </html> [/php]

as you can see, this is my form.

what i want is instant display of amount value which is QTY * unit_price

hi guys,

i end up with this script i happenly learn from others… but it still not perfect yet…

[code] [/code]

[code]

[/code]

as this script require me to press a button to calculate it. is complete half of what i asking…

What i want to instant display the result once both input a and input b is key in so that will show on c

Any help here???

I’m not sure if this is a typeo but…

this

[php]

<input type “number” value=0 name=“ans” size=9>[/php]

should be

[php]

[/php]

It’s missing the “=” sign between type and number.

is a copy paste problem… i dun know why i just ctrl A highlight and ctrl c copy and ctrl v paste it on here…

So basically, you need to add an onkeypress event to both the A and B Input that calls your function a_times_b like “onkeypress=a_times_b(this.form)”

Then in that function, you need to test if the values of a and b are both numeric and if they are multiply them.

if possible, i dun nd a keypress. just like using tab will able to count.

and also if possible, i would like to put in as many row as possible…

my current code only allow me to put in one code per time.

is there any way i can put in like 10 rows per page and able to insert to database in 10 rows too

You can change it to onkeyup instead of onkeypress to capture the tab key.

And yes you can make 10 rows at a time you’ll just need to do a foreach statement and create an unique ID for each of the input boxes.

did you have any example on using onkeyup event? i dun hv any idea on using it.

this is my current form

[php]

<?php session_start(); if (isset($_SESSION['user']) && !empty($_SESSION['user'])) { echo "Welcome " . $_SESSION['user']; include 'tabmenuOneForAll.php'; ?>
     <?php

include 'config.php';

mysql_connect($server, $db_user, $db_pass);

if (isset($_POST['upload'])) {

$trx_id = $_POST['trx_id'];
$product_name = $_POST['product_name'];    	
$qty = $_POST['a'];
$unit_price = $_POST['b'];
$description = $_POST['description'];   
$amount = $_POST['ans'];


  $query_insert = "INSERT INTO trx_record (trx_id, product_name, unit_price, amount, remarks, created)". 

“VALUE (’$trx_id’, ‘$product_name’, ‘$unit_price’, ‘$amount’, ‘$remarks’, now())”;

    $result_insert = mysql_query($query_insert);

    header("Location: add_trx.php=$row[id]");

    $id = $user_id;
} else {
    $id = $_GET['id'];
}

$query = "SELECT * FROM transaction WHERE id = {$id}";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);

//header("Location: edit_client.php?update=".$result."");

//header("Location: view_client.php");

?>












  <tr>
  <td>Address :</td>
  <td><input type="text" name="company_address" size="20" value="<?php echo $row['c_address'] ?>" disabled = "disabled"></td>
  </tr>
  </table>
  <center>

  <table cellpadding="3" border accesskey="1">
  <tr>
    <td>Item Description</td>
    <td>Quantity</td>
    <td>Unit Price</td>
    <td>Amount</td>
    </tr>
          <tr>
            <td></td><td></td><td></td>
            <td align="right"><input type="submit"  name="submit" value="submit"></td>
          </tr>
  </table>
  </center>
  </form>
 </html>  
  <?php

} else {
header(“location:login.php”);
}

?>

[/php]

but i do get an error msg upon submit.

Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in

what does it mean?

Invoice NO
Customer Name :
<?php

include ‘config.php’;

mysql_connect($server, $db_user, $db_pass);
mysql_select_db(‘sthmotor’);

$sql = “SELECT product_name FROM product”;
$result = mysql_query($sql);

echo “”;
while ($row = mysql_fetch_array($result)) {
echo “<option value=’” . $row[‘product_name’] . “’>” . $row[‘product_name’] . “”;

}
echo “”;

?>

Strange, you don’t even have mysql_fetch_row in your code…

Anyway, read here

Please also take time to read their comments about sql injection, it applies to you as well ^^

oh… my bad… i just change to assoc …

so is working… but the injection still working…

ok. i manage to do the injection. without errors.

so here is my another question …

during my form insert statetment, in my url is something like this

http://localhost/sth_inventory/html/add_trx.php?id=1

bcoz i nd to get the information from another table.

but i may nd to submit more then once for this form. so i redirect it the the same page again until the user decide to exit it.

what is the best solution when page is refresh, the id=1 still remain?

[php]onkeyup=a_times_b(this.form)[/php]

cant… i onkeyup cant perform the task

I’m sorry, I just don’t understand what you’re trying to say.

hi topcoder,

sorry for the late reply… been sick for days…

what i mean was even i apply the onkeyup event, i still need to press the button.

so i wonder if there is any possible that im able to do it without click it? just like key in the quantity and unit price then directly the amount is shown on the amount column

you can apply that even listener to any input. instead of tying to the button, tie it to the last input box. Just put something in there to make sure the first field isn’t empty.

Just like Richei said…

You can add the event to any HTML except:
, ,
, , ,

So the below is what you’re looking for.

[php]

[/php]

And check it for empty like Richei said.

Sponsor our Newsletter | Privacy Policy | Terms of Service