0

Could someone help me iterate or loop the output from my computation in all the text input from my table? The output displays but only in one row and doesn't display in the other row of the table. Helping me solve this one is much more appreciated.

<head>
<script language="javascript" type="text/javascript">

function calculateSellingPrice()
{
   var txtcost = document.getElementById("cost");
   var txtsellingprice = document.getElementById("sellingprice");
   var txtprofit = document.getElementById("profit");


  //find the total first
  var total = parseFloat(txtcost.value) + parseFloat(txtpostage.value);

  //for selling price computation
  txtsellingprice.value = total;

 //for ebay fees computation
 if (txtsellingprice.value > 50){
   txtebayfees.value = parseFloat(txtsellingprice.value - 50) * 0.05 + 3.5;
 }
 else if (txtsellingprice.value <= 50){
 txtebayfees.value = parseFloat(txtsellingprice.value) * 0.07;
 }
 }
//-->
</script>

</head>
<body onload="calculateSellingPrice();">    
<table> 
  <tr>
    <td><center>SKU</center></td>
    <td><center>Selling Price</center></td>
    <td><center>Cost</center></td>
  </tr>    
      <?php
      $result = mysql_query("SELECT sku, sellingprice FROM tbl_inventory");                               
      while ($myrow = mysql_fetch_row($result))
      { 
    ?>
      <tr>
    <td>
       <?php echo "<input type='text' id='sku' name='sku' />"; ?>
    </td>
    <td>
       <?php echo "<input type='text' id='sellingprice' name='sellingprice' />"; ?>
    </td>
    <td>
       <?php echo "<input type='text' id='cost' name='cost' />"; ?>
    </td>
     </tr>  
    <?php>
    }
    ?>
</table>
2
  • Are you asking how to fix your PHP template file so it will output into multiple rows? Or are you asking how to do something client-side using javascript? Your question is not clear as written. Also, if you're not asking a PHP question, then please post the generated javascript that the browser sees (you can use View/Source in your browser to capture it) so we can see what the browser actually sees.
    – jfriend00
    Dec 16, 2011 at 3:18
  • I am looking for some client-side calculation using javascript and iterate the the calculated data on the input text. Can you give me some related idea with this?
    – jovazel
    Dec 16, 2011 at 9:33

2 Answers 2

0

Just to point some issues, you are querying your table, and you need to calculate based on the returned value, right?

Perhaps you need a value to calculate something.. see bellow how I did..

<?php echo "<input type='text' id='sellingprice' name='sellingprice' value='".$myrow['sellingprice']."' />"; ?>

you are missing this part -> value='".$myrow['sellingprice']."'

0

Firstly: Don't write bolt please.

Second: If you need a table, use jQuery Plugin Datatables.net. It is awesome!

Just create an numeric array which looks like this in PHP:

$x = array(0 => array(
            0 => 'this is a name',
            1 => 'this is a price',
            2 => 'this is a x')
      0 => array(
            0 => 'this is a name',
            1 => 'this is a price',
            2 => 'this is a x')
);

Then do json_encode(array('aaDara => $x));

And use it as a AjaxSource. It's really nice!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.