Basic $_POST not working for javascript generated value
Posted: Tue Aug 26, 2008 6:07 am
Hi Experts,
I have a page that calculates the Amount using javascript when the user keys in the quantity. In the action page, When I call for the value using $_REQUEST['untSubtotal']; the value dosent get displayed. But other fields are displayed in my next page. Note untSubtotal is populated by Javascript. Can any one point my mistake? or any other Ideas of doing it or suggestions. I've posted the codes of my both pages form page and the action page.
See image screen1 (form page)
Below is the code for screen1:
This is the action page screen2: attached is the image of the look. In the below page, Im able to dispaly all the values except the ones populated by the javascript. Can any one spot why its not getting displayed.
Can any one spot my mistake please? Ive been breaking my head with this for super long time now
Thank you
I have a page that calculates the Amount using javascript when the user keys in the quantity. In the action page, When I call for the value using $_REQUEST['untSubtotal']; the value dosent get displayed. But other fields are displayed in my next page. Note untSubtotal is populated by Javascript. Can any one point my mistake? or any other Ideas of doing it or suggestions. I've posted the codes of my both pages form page and the action page.
See image screen1 (form page)
Below is the code for screen1:
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php include($mosConfig_live_site."development/b1g1f/Connections/b1g1.php"); ?>
<head>
<?php $this_site_domain = "http://".$_SERVER['SERVER_NAME']."/"; ?>
<LINK REL=StyleSheet HREF="<?=$this_site_domain?>templates/css/extra.css" TYPE="text/css" MEDIA=screen>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title>Project Payment</title>
</head>
<?php
session_start();
global $my;
$joomlaid = $my->id;
$_SESSION['id'] = $joomlaid;
$projectToContribute = $_POST['projectToContribute'];
echo "projectToContribute: ".$projectToContribute;
$queryProjects = mysql_query("Select p.PartneringID As PartnerIDs,p.BusinessProductCustRef,p.BusinessProductName
,c.ContributionUnitAmt,c.ContributionTotalAmt,c.ContributionType
,c.ContributionSalesQty,pj.ProjectTitle, pj.ProjectPicURL,pj.ProjectStory From tbl_partnering_data As p INNER JOIN tbl_contribution_payments as c ON p.PartneringID = c.PartneringID INNER JOIN tbl_projects as pj
ON pj.ProjectID = p.ProjectIDRef WHERE c.ContributionPaidOK = 0 AND c.ContributionJosUserID =".$joomlaid." AND p.PartneringID=".$projectToContribute);
?>
<body>
<form action="next.php" name="payForm" method="post" onSubmit="return submitbutton_reg()">
<table>
<tr>
<td width="" height="111" valign="top"><span class="contentheading">Instructions</span><br />
<ul>
<li>Add the sales quantity for the last period for each of the products you wish to contribute today.</li>
<li>If Start Period and End Date fields are shown, you can optionally complete them - they are for your record. <strong>Enter the dates in format DD/MM/YYYY e.g. (24/05/2008)</strong></li>
</ul></td>
</tr>
<tr>
<td valign="top"><a href="http://www.buy1-give1free.com/index.php?option=com_content&task=view&id=396&Itemid=395&view=all">View all past contributions</a></td>
</tr>
</table>
<?php
while($getProj = mysql_fetch_array($queryProjects)){
$projName = $getProj['ProjectTitle'];
$projDesc = substr($getProj['ProjectStory'], 0, 80);
$bizRef = $getProj['BusinessProductCustRef'];
$bizProName = $getProj['BusinessProductName'];
$unitValue = $getProj['ContributionUnitAmt'];
$conType = $getProj['ContributionType'];
?>
<table width="710" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" class="tblTH tblHB" colspan="2">Project</td>
<td align="center" class="tblTH tblHB tblTHBL">Sales Description</td>
<td align="center" class="tblTH tblHB tblTHBL">Your Product Reference</td>
<?php if($conType=="R"){ ?>
<td align="center" class="tblTH tblHB tblTHBL">Start Date<br />(DD/MM/YYYY)</td>
<td align="center" class="tblTH tblHB tblTHBL">End Date<br />(DD/MM/YYYY)</td>
<?php }?>
<td align="center" class="tblTH tblHB tblTHBL">Unit Value USD</td>
<td align="center" class="tblTH tblHB tblTHBL">Qty</td>
<td align="center" class="tblTH tblHB tblTHBL">Amount USD</td>
</tr>
<tr>
<td align="center" class="tblTD tblBT tblBL" colspan="2"><?=$projName?></td>
<td align="center" class="tblTD tblBT tblBL"><?=$projDesc?></td>
<td align="center" class="tblTD tblBT tblBL"><input maxlength="11" type="text" value="<?=$bizProName?>" name="busProductName" id="busProductName" /></td>
<?php if($conType=="R"){ ?>
<td align="center" class="tblTD tblBT tblBL"><input class="YellowTextBoxMidTwo" maxlength="11" type="text" name="startDate" id="startDate" /></td>
<td align="center" class="tblTD tblBT tblBL"><input class="YellowTextBoxMidTwo" maxlength="11" type="text" name="endDate" id="endDate" /></td>
<?php } ?>
<td align="center" class="tblTD tblBT tblBL"><?=$unitValue?>
<input id="unitPrice" name="unitPrice" type="hidden" value="<?=$unitValue?>"/></td>
<td align="center" class="tblTD tblBT tblBL tblBR"><input class="YellowTextBoxNarrowTwo" maxlength="7" size="7" name="qty"
id="qty" type="text" value="" onchange="readQty('qty')"/></td>
<td align="center" class="tblTD tblBT tblBL"><input maxlength="7" size="7" name='untSubtotal' id='untSubtotal' type='text' style="text-align:right;" value="" disabled /></td>
</tr>
<tr>
<?php
}// while loop
?>
<tr>
<td valign="top" align="right" class="tblTH tblHB" colspan="<?php if($conType=="R"){ echo 9; }else{ echo 7; } ?>"><strong>Total Amount USD</strong>
<input style="background: #FF9900; text-align:center; font-weight:bold; color:black;" size='7' name='grandTotal' id='grandTotal' type='text' value='' disabled />
<input name="projName" type="hidden" value="<?=$projName?>"/>
<input name="projDesc" type="hidden" value="<?=$projDesc?>"/>
<input name="bizProName" type="hidden" value="<?=$bizProName?>"/>
</td>
</tr>
<tr>
<td align="center" class="tblBT"> </td>
<td align="center" class="tblBT"> </td>
<td align="center" class="tblBT"> </td>
<td align="center" class="tblBT"> </td>
<td align="center" class="tblBT"> </td>
<td align="center" class="tblBT"> </td>
<td align="center" class="tblBT"> </td>
<td align="center" class="tblBT"> </td>
<td align="center" class="tblBT"> </td>
</tr>
<tr>
<td><div align="right"></div></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td colspan="3" align="right"><input type="image" src="../../../images/ContributeNow.jpg" name="lets-do-it" border="0" id="lets-do-it"></td>
</tr>
<tr>
<td></td>
<td></td>
<td> </td>
<td colspan="7" align="right" valign="middle">
<img src="../../../images/SecureServer.jpg" width="131" height="70" align="absmiddle"><img src=\
"../../../images/poweredByWorldPay.gif" width="139" height="33" align="middle"/><img src="../../images/masterC.PNG" alt="MasterCard"
width="38" height="26" align="middle" /><img src="../../images/visa.PNG" alt="VisaCard" width="41" height="27" align="middle"/>
<img src="../../images/amex.gif" alt="Amex" align="middle"/><br></td>
</tr>
</table>
</form>
<script language="javascript">
var qty, unitPrice, subtotal;
total = 0;
function readQty(qtyfield){
qty = document.getElementById(qtyfield).value;
qty = qty * 1;
if (isNaN(qty)) {
qty = 0;
alert("Quantity have to be numerical");
document.getElementById(qtyfield).focus();
}
getSubtotal();
}
function getSubtotal(){
unitPrice = document.getElementById("unitPrice").value;
subtotal = unitPrice * qty;
document.getElementById("untSubtotal").value = subtotal.toFixed(2);
grandTotal = document.getElementById("untSubtotal").value*1;
document.getElementById("grandTotal").value = grandTotal.toFixed(2);
}
function submitbutton_reg(){
qty = document.getElementById(qty).value;
qty = qty * 1;
if(isNaN(qty) || document.getElementById("qty").value<=0){
qty = 0;
alert("Please enter a numerical quantity of sales.");
document.getElementById("qty").focus();
return false;
}else if (document.getElementById("startDate").value<9) {
alert("Please enter the start date in format DD/MM/YYYY e.g. (24/05/2008)");
document.getElementById("startDate").focus();
return false;
}else if (document.getElementById("endDate").value<9) {
alert("Please enter the start date in format DD/MM/YYYY e.g. (24/05/2008)");
document.getElementById("endDate").focus();
return false;
}
return true;
}
</script>
</body>
</html>This is the action page screen2: attached is the image of the look. In the below page, Im able to dispaly all the values except the ones populated by the javascript. Can any one spot why its not getting displayed.
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<?php include($mosConfig_live_site."development/b1g1f/Connections/b1g1.php");
$this_site_domain = "http://".$_SERVER['SERVER_NAME']."/";
?>
<LINK REL=StyleSheet HREF="<?=$this_site_domain?>templates/css/extra.css" TYPE="text/css" MEDIA=screen>
</head>
<body>
<form action="https://select.worldpay.com/wcc/purchase" method="post" name="PartneringContribution">
<table width="600" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" class="tblTH tblHB">Project</td>
<td align="center" class="tblTH tblHB tblTHBL">Your Product Reference</td>
<td align="center" class="tblTH tblHB tblTHBL">Unit Price USD</td>
<td align="center" class="tblTH tblHB tblTHBL">Qty</td>
<td align="center" class="tblTH tblHB tblTHBL">Amount USD</td>
</tr>
<?php
session_start();
$busProductName = $_POST['busProductName'];
echo 'busProductName '.$_REQUEST['busProductName'].'<br>';
echo 'startDate '.$_REQUEST['startDate'].'<br>';
echo 'endDate '.$_REQUEST['endDate'].'<br>';
echo 'unitPrice '.$_REQUEST['unitPrice'].'<br>';
echo 'qty '.$_REQUEST['qty'].'<br>';
echo 'subtotal '.$_REQUEST['untSubtotal'].'<br>';
echo 'grandTotal '.$_REQUEST['grandTotal'].'<br>';
?>
<tr>
<td align='center' class='tblTD tblBT tblBL'><?=$_POST['projName']?></td>
<td align='center' class='tblTD tblBT tblBL'><?=$_POST['busProductName']?></td>
<td align='center' class='tblTD tblBT tblBL'><?=$_POST['unitPrice']?></td>
<td align='center' class='tblTD tblBT tblBL'><?=$_POST['qty']?></td>
<td align='center' class='tblTD tblBT tblBL tblBR'><?=$_POST['untSubtotal']?></td>
</td>
</tr>
<tr>
<td align='right' class='tblTH tblHB tblTHBB' colspan='4'><b>Total USD</b></td>
<td align='center' class='tblTD tblBT tblBL tblBR tblTHBB'><b><?=$_POST['grandTotal']?></b>
<input name="projName" type="hidden" value="<?=$_POST['projName']?>" />
<input name="busProductName" type="hidden" value="<?=$_POST['busProductName']?>" />
<input name="unitPrice" type="hidden" value="<?=$_POST['unitPrice']?>" />
<input name="qty" type="hidden" value="<?=$_POST['qty']?>" />
<input name="subtotal" type="hidden" value="<?=$_POST['subtotal']?>" />
<input name="grandTotal" type="hidden" value="<?=$_POST['grandTotal']?>" />
</td>
</tr>
<tr>
<td align="right" colspan="5">
<input name="button" value="Submit" type="image" src="../../images/OK-go-ahead-Now.jpg"/>
</td>
</tr>
<tr>
<td colspan="5" align="right" valign="middle">
<img src="../../../images/SecureServer.jpg" width="131" height="70" align="absmiddle"><img src=\
"../../../images/poweredByWorldPay.gif" width="139" height="33" align="middle"/><img src="../../images/masterC.PNG" alt="MasterCard"
width="38" height="26" align="middle" /><img src="../../images/visa.PNG" alt="VisaCard" width="41" height="27" align="middle"/>
<img src="../../images/amex.gif" alt="Amex" align="middle"/><br></td>
</tr>
</table>
<input type="hidden" name="instId" value="433432">
<input type="hidden" name="cartId" value="<?=$_SESSION['id']?>">
<input type="hidden" name="amount" value="<?=$_POST['grandTotal']?>">
<input type="hidden" name="currency" value="USD">
<input type="hidden" name="desc" value="Partnering Contribution">
<input type="hidden" name="MC_joomlaid" value="<?=$_SESSION['id']?>">
<input type="hidden" name="MC_amountpaid" value="<?=$_POST['grandTotal']?>">
<input type="hidden" name="MC_transid" value="<?=$_SESSION['partnerIDs']?>">
<input type="hidden" name="MC_process" value="true">
<input type="hidden" name="MC_FromPage" value="Partnering Contribution Recurring">
<input type="hidden" name="testMode" value="100">
</form>
<script language="javascript">
var qty, unitPrice, subtotal, i;
var count=<?=$i?>;
var dateCount=<?=$j?>;
var total = 0;
total = total*1;
function readQty(fieldname,unitfieldname,subtotalfieldname,incrementer){
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);
total = 0;
for(i=1;i<=count;i++){
total = total + (document.getElementById("subtotal"+i).value*1);
}
document.PartneringContribution.total.value = total.toFixed(2);
}
function submitForm(){
var form = document.PartneringContribution.submit();
}
</script>
</body>
</html>
Thank you