Jump to content

problem in document.getElementById where value is from array


newphpcoder

Recommended Posts

Hi..

 

I have problem on how can I automatically display the output from the computation (Demanded Qty * Quantity), after or while I input Demanded Qty.

 

I mean I input Demanded Qty, on below it will display the output also beside the SubItems.

 

Sorry, if i post again my problem, because I have no idea on how can I solve this problem.

 

here is my code:

 

<?php                                                                          
   error_reporting(0);
   date_default_timezone_set("Asia/Singapore"); //set the time zone  
$con = mysql_connect('localhost', 'root','');

if (!$con) {
    echo 'failed';
    die();
}
mysql_select_db("mes", $con);
?>
<html>
<title>Stock Requisition</title>
<head>
<link rel="stylesheet" type="text/css" href="kanban.css">
<script type="text/javascript">
function compute_quantity(){
    var DemandedQty = document.getElementById('DemandedQty').value;
    var SubQty = document.getElementById('SubQty').value;
    var Quantity = document.getElementById('Quantity').value;
    
     SubQty = (DemandedQty * Quantity);
}
</script>
</head>
<body>
<form name="stock_requisition" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<div>
<table>
<thead>
<th>Items</th>
<th>Sub Items</th>
<th>Item Code</th>
<th>Demanded Qty</th>
<th>UoM</th>
<th>Class</th>
<th>Description</th>
<th>BIN Location</th>
</thead>
<?php

$DemandedQty = $_POST['DemandedQty'];

$sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items";
$res_bom = mysql_query($sql, $con);

while($row = mysql_fetch_assoc($res_bom)){
    
    $Items = $row['Items'];
    $Items_ = substr($Items, 12, 3);
    
echo "<tr>
        <td style='border: none;font-weight: bold;'> <input type='name' value='$Items_' name='Items_[]' id='Items' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td>
        <td style='border:none;'> </td>
        <td style='border:none;'> </td> 
        <td style='border: none;'><center><input type='text' name='DemandedQty[]' id='DemandedQty' value='' size='12' onkeyup = compute_quantity()></center></td>     
        </tr>"; 
             
$sql = "SELECT Items, SubItems, ItemCode, UoM, Class, Description, BINLocation, Quantity FROM bom_subitems WHERE Items = '$Items' ORDER BY Items"or die(mysql_error());

$res_sub = mysql_query($sql, $con);  

while($row_sub = mysql_fetch_assoc($res_sub)){

     $Items1 = $row_sub['Items'];
     $SubItems = $row_sub['SubItems'];
     $ItemCode = $row_sub['ItemCode'];
     $UoM = $row_sub['UoM'];
     $Class = $row_sub['Class'];
     $Description = $row_sub['Description'];
     $BINLocation = $row_sub['BINLocation'];
     $Quantity = $row_sub['Quantity']; 
      
    echo "<input type='hidden' name='Quantity' id='Quantity' value='$Quantity'>";
    echo "<tr>
        <td style='border: none;'> <input type='hidden' value='$Items1' id='Items1' name='Items1[]'></td>
        <td style='border: none;'> <input type='text' name='SubItems[]' value='$SubItems' id='SubItems' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td>
        <td style='border: none;'> <input type='text' name='ItemCode[]' value='$ItemCode' id='ItemCode' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td>
        <td style='border: none;'><center><input type='text' name='SubQty[]' id='SubQty' value='' size='12' style></center></td>
        <td style='border: none;' size='3'> <input type='text' name='UoM[]' value='$UoM' id='UoM' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='3'></td>
        <td style='border: none;'> <input type='text' name='Class[]' value='$Class' id='Class' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td>
        <td style='border: none;'> <input type='text' name='Description[]' value='$Description' id='Description' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size= '30'></td>
        <td style='border: none;'> <input type='text' name='BINLocation[]' value='$BINLocation' id='BINLocation' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td>     
        </tr>";    
        
}
}               
?>
</table>
</div>
</form>
</body>
</html>

 

If  you don't understand my issue feel free to ask me for further understanding.

 

I'm sorry again I really need to solve this and i tried to google but I can't find the solution.

 

Thank you so much

post-101569-134824034714_thumb.jpg

Link to comment
Share on other sites

Hi..

 

I revise my function for auto compute and display of demanded qty per subitems, but it happened now is only the first Sub Items got an output, and also it works only on the first Items which is P28, when I tried to inpt demanded Qty in Items = P30 it did not work, no data display for subitems.

 

Now I don't know how can I loop it and to check if in where Items Demanded Qty I was input Qty and also how can does display the Qty in Sub Items, because now it only display on first row.

 

<?php                                                                          
   error_reporting(0);
   date_default_timezone_set("Asia/Singapore"); //set the time zone  
$con = mysql_connect('localhost', 'root','');

if (!$con) {
    echo 'failed';
    die();
}

mysql_select_db("mes", $con);
?>
<html>
<title>Stock Requisition</title>
<head>
<link rel="stylesheet" type="text/css" href="kanban.css">


<script language="JavaScript">
function CheckTextbox() {
var Items_;    
var DemandedQty;
var SubQty;
var Quantity;
// first set a reference to the textbox 
Items_ = document.getElementById('Items_');
DemandedQty = document.getElementById('DemandedQty');
SubQty = document.getElementById('SubQty');
Quantity = document.getElementById('Quantity');

if (DemandedQty.value != "") {
SubQty.value = DemandedQty.value * Quantity.value;
} else {

alert('nope');
}
}
</script> 

</head>
<body>
<form name="stock_requisition" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<div>
<table>
<thead>
<th>Items</th>
<th>Sub Items</th>
<th>Item Code</th>
<th>Demanded Qty</th>
<th>UoM</th>
<th>Class</th>
<th>Description</th>
<th>BIN Location</th>
</thead>
<?php

$DemandedQty = $_POST['DemandedQty'];

$sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items";
$res_bom = mysql_query($sql, $con);

while($row = mysql_fetch_assoc($res_bom)){
    
    $Items = $row['Items'];
    $Items_ = substr($Items, 12, 3);
    
echo "<tr>
        <td style='border: none;font-weight: bold;'> <input type='name' value='$Items_' name='Items_[]' id='Items_' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td>
        <td style='border:none;'> </td>
        <td style='border:none;'> </td> 
        <td style='border: none;'><center><input type='text' name='DemandedQty[]' id='DemandedQty' value='' size='12' onkeyup = CheckTextbox()></center></td>     
        </tr>"; 
             
$sql = "SELECT Items, SubItems, ItemCode, UoM, Class, Description, BINLocation, Quantity FROM bom_subitems WHERE Items = '$Items' ORDER BY Items"or die(mysql_error());

$res_sub = mysql_query($sql, $con);  

while($row_sub = mysql_fetch_assoc($res_sub)){

     $Items1 = $row_sub['Items'];
     $SubItems = $row_sub['SubItems'];
     $ItemCode = $row_sub['ItemCode'];
     $UoM = $row_sub['UoM'];
     $Class = $row_sub['Class'];
     $Description = $row_sub['Description'];
     $BINLocation = $row_sub['BINLocation'];
     $Quantity = $row_sub['Quantity']; 

    echo "<input type='hidden' name='Quantity' id='Quantity' value='$Quantity'>";
    echo "<tr>
        <td style='border: none;'> <input type='hidden' value='$Items1' id='Items1' name='Items1[]'></td>
        <td style='border: none;'> <input type='text' name='SubItems[]' value='$SubItems' id='SubItems' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td>
        <td style='border: none;'> <input type='text' name='ItemCode[]' value='$ItemCode' id='ItemCode' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td>
        <td style='border: none;'><center><input type='text' name='SubQty[]' id='SubQty' value='' size='12' style></center></td>
        <td style='border: none;' size='3'> <input type='text' name='UoM[]' value='$UoM' id='UoM' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='3'></td>
        <td style='border: none;'> <input type='text' name='Class[]' value='$Class' id='Class' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td>
        <td style='border: none;'> <input type='text' name='Description[]' value='$Description' id='Description' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size= '30'></td>
        <td style='border: none;'> <input type='text' name='BINLocation[]' value='$BINLocation' id='BINLocation' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td>     
        </tr>";    
        
}
}               
?>
</table>
</div>
</form>
</body>
</html>


 

Thank you so much

post-101569-13482403471746_thumb.jpg

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.