Hi,

I am trying to develop a battery order form. Here is the problem.

User has to enter the "Current Stock". There is a "Allowed Stock" for each row. What I want to accomplish is when a user puts in the "Current Stock", I want the "Request Stock" to appear after the value changes.

Request Stock = Allowed Stock - Current Stock

I managed to code the request stock but now the problem is storing those values in an array and passing them on in the POST. I dont know how to do that.

Attached is the code snippets...

//Script function
 
function requestItems(theField)
{
  var curStock = parseInt(theField.value);
  var theRow = theField.parentNode;
  var temp = 0;
  while(theRow&&theRow.nodeName!="TR")
  {             
        theRow=theRow.parentNode;
  }
    if(theRow)
        {
                temp = theRow.cells[2].innerHTML-curStock;
        if(temp < 0){
          theRow.cells[3].innerHTML = 0;}
        else{
          theRow.cells[3].innerHTML = temp;}
           }
        }
 
 
//Form Field
 
<form id="bte_battery" name="bte_battery_form" enctype='multipart/form-data' action='<?=$url['frontPOST']?>' method='post'>
 
 
// PHP Script
 
for($i=0; $i<sizeof($item); $i++)
{
  echo "<tr>";
  echo "<td style='text-align: left'>";
  echo $item[$i]['type'];
  echo "</td>";
                        
  echo  "<td style='text-align: center'><input type='text' name='quantity[]' id='quantity_" . $i . "' value=0 onkeyup='requestItems(this)' style='width: 50px; padding: 2px; text-align: right; border-color:#4f94cd; border-width:thin; border-style:solid'></td>";
                        
                        
  echo "<td style='text-align: center; padding: 2px;'>";
  echo $item[$i]['level'][$level];
  echo "</td>";
                        
  echo "<td style='text-align: center; padding: 2px;'>";
  echo "</td>";                 
 
  echo "</tr>";                         
   }                    
                        
        }

How do I allocate the "value" in the second TD?

Attached is an image of the page. What I want to do is capture CurrentStock and Request Stock into an array and send it to next page.

What modifications do I need to make in the requestItems script?

Attachments phpjscript3.jpg 26.65 KB

I managed to code the request stock but now the problem is storing those values in an array and passing them on in the POST. I dont know how to do that.

To pass HTTP params as an array, use the array notation, eg: item[]

<input name="item[]" />

PHP will parse the "item" parameter into an indexed array available in: $_POST

This article has been dead for over six months. Start a new discussion instead.