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

Am not sure if this is what you need!
But i hope this example wil lighten up things! With following demo, I simply convert all values' into arrays and then pass it into the designated cell.
Just don't forget to evaluate all needed data in your php code! Well that's all for now and good day to you...

<html>
<head>
<title><!-- Sample --></title>
<script type="text/javascript">
<!--
document.onchange = function( e ) 
{ e = e ? e : window.event;
  t = e.target ? e.target : e.srcElement;
var myval = [];
var thisInput = document.form1; 
var thisClaim = document.getElementsByTagName('td');

myval[myval.length] = eval(thisClaim['rs0'].innerText)
myval[myval.length] = eval(thisClaim['rs1'].innerText)
myval[myval.length] = eval(thisClaim['rs2'].innerText)

if (( t.name ) && (t.name == 'cs1')) 
{ myval[0] = myval[0] - eval(thisInput.cs1.value) }
if (( t.name ) && (t.name == 'cs2')) 
{ myval[1] = myval[1] - eval(thisInput.cs2.value) }
if (( t.name ) && (t.name == 'cs3')) 
{ myval[2] = myval[2] - eval(thisInput.cs3.value) }
 if ( myval.length > 0 ) {
 total(myval);  
 }
}

function total( myval ) 
{ for ( var i = 0; i < myval.length; i++ ) { document.getElementsByTagName('td')['rs' + i].innerText = myval[i]; } 
}
//-->
</script>
<style type="text/css">
<!--
body { margin: 0px auto }

form { 
          width: 427px; 
          font: 14px/20px Arial, Helvetica, sans-serif; 
          color: #A5A5A4; 
          margin: 0 0 0 0;
   }
form fieldset { 
     margin: 2px;
     padding: 4px; 
     border: 2px solid #000088;
     
}
form table { 
     border: none; 
     margin: 2px;
     width: 70%;
}
table td { 
     color: #000066; 
     text-align: center;
     font: 10px/16px Arial, Helvetica, sans-serif;
}
table.mtitle td { 
     color: #000066; 
     text-align: left;
     font: 10px/16px Arial, Helvetica, sans-serif;
}
table th { 
     color: blue; 
     text-align: center;
     font: 14px/20px Arial, Helvetica, sans-serif;
}
fieldset legend {
    font-weight: bold; 
    color: #000088;
}
 
-->
</style>
</head>
<body>

<form name="form1" action"javascript:void(0)" onsubmit="return false;">
<fieldset>
  <legend><nobr>&nbsp;Dispenser Information&nbsp;</nobr></legend>
<table class="mtitle">
<tr rowspan="3">
<td>Name*</td>
<td>Jerry Boudreau</td>
</tr>
<td>Location*</td>
<td> R1-Middletow</td>
</tr>
<td>Change Dispenser / Location</td>
</tr>
</table>
</fieldset>

<fieldset>
<legend><nobr>&nbsp;Inventory Information&nbsp;</nobr></legend>
<table>
<thead>
<tr>
<th abbr="Type" scope="col" title="type">Type</th>
<th abbr="Current Stock" scope="col" title="Current Stock"><font color="salmon">Current Stock</font></th>
<th abbr="Allowed Stock" scope="col" title="Allowed Stock">Allowed Stock</th>
<th abbr="Request Stock" scope="col" title="Request Stock"><font color="salmon">Request Stock</font></th>
</tr>
</thead>
<tfoot>
							<tr>
		
</tr>
						</tfoot>
<tbody>
<tr>
<td colspan="1"><label>4pk#10</label></td>
<td>
<input name="cs1" type="text" value="0" size="3" />
</td>
<td id="as0">100</td>
<td id="rs0">100</td>
</tr>
<tr>
<td><label>4pk#13</label></td>
<td><input name="cs2" type="text" value="0" size="3" />
</td>
<td id="as1">100</td>
<td id="rs1">100</td>
</tr>
<tr>
<td><label>4pk#312</label></td>
<td><input name="cs3" type="text" value="0" size="3" />
</td>
<td id="as2">100</td>
<td id="rs2">100</td>
</tr>
</tbody>
</table>
<input type="submit" value="Submit" style="background-color: #000088; color: #C0C0C0; border: none; margin-left: 8px;" />&nbsp;
<input type="reset" value="Reset" style="background-color: #000088; color: #C0C0C0; border: none; " />
</fieldset>
</form>

</body>
</html>
This article has been dead for over six months. Start a new discussion instead.