Page 1 of 1

post data not working

Posted: Mon Aug 25, 2008 4:26 am
by arunkar
Hi Experts,

I have an form page (see attached image con_pg1_form.png). In the form when the quantity (qty) is added the Amount field is auto computed.
below is code for the form page:

Code: Select all

 <?php
 
        $i = 1;
        $j = 0;
        $totalRec=0;
        $total = 0.00;
        
        //session_start();
        $_SESSION['partnerIDs']="";
        
        while($getProj = mysql_fetch_array($queryProjects)){
            $partnerID = $getProj['PartnerIDs'];
            $projName = $getProj['ProjectTitle'];
            $projDesc = substr($getProj['ProjectStory'], 0, 80);
            $projPicURL = $getProj['ProjectPicURL'];
            $bizRef = $getProj['BusinessProductCustRef'];
            $bizProName = $getProj['BusinessProductName'];
            $unitValue = $getProj['ContributionUnitAmt'];
            $conType = $getProj['ContributionType'];
 
            $total = $total + $subtotal;
            //echo "<td class='tblTD tblBT tblBL' align='center' width=142 height=100><img src='".$projPicURL."' /></td>";
            echo "<td colspan='2' class='tblTD tblBT tblBL' valign='top'><strong>".$projName."</strong><br />";
            echo $projDesc."... </td>";
            echo "<td class='tblTD tblBT tblBL' valign='top' align='center'>".$bizProName."</td>";
            echo "<td class='tblTD tblBT tblBL' valign='top' align='center'><input  name='ref".$i."' class='YellowTextBoxMid' 
                    maxlength=\"7\" type='text' value='".$bizRef."'/>";
            
            if($conType=="R"){
                $j = $j +1;
                echo "<td class='tblTD tblBT tblBL' valign=\"top\" align=\"center\"><input class='YellowTextBoxMidTwo' maxlength=\"11\"     name='startDate".$j."' id='startDate".$j."' type=\"text\" value=\"\" />";
                echo "<td class='tblTD tblBT tblBL' valign=\"top\" align=\"center\"><input class='YellowTextBoxMidTwo' maxlength=\"11\"    name='endDate".$j."' id='endDate".$j."' type=\"text\" value=\"\" />";
            }
            else if($conType=="C"){
                $j = $j +1;
                echo "<td class='tblTD tblBT tblBL' valign=\"top\" align=\"center\"><input name='startDate".$j."' id='startDate".$j."' type=\"hidden\" value=\"\" />";
                echo "<td class='tblTD tblBT tblBL' valign=\"top\" align=\"center\"><input name='endDate".$j."' id='endDate".$j."' type=\"hidden\" value=\"\" />";
            }
            
            echo "<td class='tblTD tblBT tblBL' valign='top' align='center'>".$unitValue."</td>";
            echo "<td class='tblTD tblBT tblBL' valign=\"top\" align=\"center\"><input class='YellowTextBoxNarrowTwo' 
                maxlength=\"7\" size=\"7\" name=\"qty".$i."\" 
                id=\"qty".$i."\" type=\"text\" value=\"\" onchange=\"readQty('qty".$i."','subtotal".$i."','unitPrice".$i."','".$i."','".$conType."')\"/>";
            echo "<td class='tblTD tblBT tblBL tblBR' valign='top' align='center'><input maxlength=\"7\" size=\"7\" 
                name='subtotal".$i."' id='subtotal".$i."' type='text'  style='text-align:center;'
                value='".$subtotal."' disabled /></td></tr>";
                
            echo "<input type='hidden' name='unitPrice".$i."' id='unitPrice".$i."' value='".$unitValue."' />";
            echo "<input type='hidden' name='conType".$i."' value='".$conType."' />";
            echo "<input type='hidden' name='projName".$i."' value='".$projName."' />";
            echo "<input type='hidden' name='sub".$i."' id='sub".$i."' value='".$subtotal."' />";
            echo "<input type='hidden' name='grandTotal' value='".number_format($total,2)."' />";
            
            $_SESSION['partnerIDs'] = $_SESSION['partnerIDs'] . " ".$partnerID;
            $_SESSION['totalRecords'] = $i;
            $_SESSION['regular'] = $j;
            $i = $i +1;
 
        }// while loop
            $i = $i - 1;
            $totalRec = $i;
 
            $_SESSION['partnerIDs'] = ltrim($_SESSION['partnerIDs']);
 
  ?>
    <tr>
 
In the action page (see attached image con_pg1_action.png) the Amount doesn't get displayed in the action page. I've no Idea why :banghead: ... but the quantity works... I've been breaking my head with this for super loong time now still no solution...

Experts can show me why it doesn't work...

below is the code for the action page:

Code: Select all

    <?php 
    session_start();
    $totalRecord = $_SESSION['total'];
 
    
    $i =$totalRecord;
    echo 'grandTotal '.$_POST['grandTotal'].'<br>';
    echo 'subtotal '.$_POST['subtotal4'].'<br>';
    echo 'sub4 '.$_POST['sub4'].'<br>';
    
    for($i=1; $i<=$totalRecord; $i++){
        echo "<tr>";
            echo "<td align='center' class='tblTD tblBT tblBL'>";
                echo $_POST['projName'.$i];
            echo "</td>";
            echo "<td align='center' class='tblTD tblBT tblBL'>";
                echo $_POST['ref'.$i];
            echo "</td>";
            echo "<td align='center' class='tblTD tblBT tblBL'>";
                echo $_POST['unitPrice'.$i];
            echo "</td>";
            echo "<td align='center' class='tblTD tblBT tblBL'>";
                echo $_POST['qty'.$i];
            echo "</td>";
            echo "<td align='center' class='tblTD tblBT tblBL tblBR'><b>";
                echo $_POST['sub'.$i];
                echo $_POST['unitPrice'.$i];
 
            echo "</b></td>";
        echo "</tr>";   
    }   
    
        echo "<tr>";
            echo "<td align='right' class='tblTH tblHB tblTHBB' colspan='4'><b>Total USD</b></td>";
            echo "<td align='center' class='tblTD tblBT tblBL tblBR tblTHBB'><b>";
                echo $_POST['grandTotal'];
        echo "</b></td></tr>";
?>
 
When I echo

Code: Select all

    echo 'grandTotal '.$_POST['grandTotal'].'<br>';
    echo 'subtotal '.$_POST['subtotal4'].'<br>';
    echo 'sub4 '.$_POST['sub4'].'<br>';
This is the result I get in the action page:
grandTotal 0.00
subtotal
sub4


Thanks Experts

Re: post data not working

Posted: Mon Aug 25, 2008 5:03 am
by arunkar
this is the Javascript that populates the Amount

Code: Select all

        
var qty, unitPrice, subtotal, i;
        var count=<?=$i?>;
        var dateCount=<?=$j?>;
        var total = 0;
        total = total*1;
        function readQty(fieldname,unitfieldname,subtotalfieldname,incrementer,conType){
            
            qty = document.getElementById(fieldname).value;
            qty = qty * 1;
    
            if (isNaN(qty)) {
                qty = 0;
                alert("Quantity have to be numerical");
                
                document.getElementById(fieldname).focus();
            }
            getSubtotal(unitfieldname,subtotalfieldname,incrementer,conType);
        }
 
        function getSubtotal(fieldname1,fieldname2,incrementer,conType){
        
            unitPrice = document.getElementById(fieldname2).value;
            subtotal = unitPrice * qty;
            document.getElementById(fieldname1).value = subtotal.toFixed(2);
            
            
            //count = count +1;
            total = 0;
            for(i=1;i<=count;i++){
                total = total + (document.getElementById("subtotal"+i).value*1);
                }
            document.payForm.total.value = total.toFixed(2);
            
            checkFields(incrementer,conType);
        }