Sorry I ment java script, the issue is that if I am on the java script forum then they don't know PHP, I figure more php programmers kniow java script then vise versa. As you cen see below the issues I am running into is that I have to somehow populate the existing total that already populates the total from DB but I have to get them to be able to click on a drop down and have it change the total if they choose hardcopt to add 15.00 to total and also to add that 15 to the field shipping and then also if they are from washington state to add sakles atx if they current logged on student is from hat state and I am lost as to how I would get those to add to total without replacing the existing total??? Today was the deadline to get this to work, I don't think I will be meeting it!
<?php
require 'functions.php';
include_once "common.php";
$smarty->assign("logo",GetLogo("icon/logo"));
$smarty->assign("lector_email",$session_data["EMail"]);
$smarty->assign('formattype_ids', array(1000, 1001));
$smarty->assign('formattype_names', array('Electronic','Hard Copy'));
$smarty->assign('formattype_id', 1000);
$smarty->assign('shipto_ids', array(1001, 1002, 1003, 1004, 1005, 1006));
$smarty->assign('shipto_names', array('-','Home Address 1','Home Address 2','Company Address 1','Company Address 2','Other'));
$smarty->assign('shipto_id', 1001);
$smarty->assign('purchtype_radios', array(1001,1002,));
$smarty->assign('purchtype_names', array('Standard','Shared Text'));
$smarty->assign('purchtype_id', 1001);
$smarty->assign('paymentmethod_ids', array(1000,1001,1002,1003,1004));
$smarty->assign('paymentmethod_names', array('-','Visa','MasterCard','American Express','Check'));
$smarty->assign('paymentmethod_id', 1000);
if (isset($session_data["CurStudent"]))
{
//I left out the usual connection stuff and current student stuff
if (isset($cur))
{
if (!($result = mysql_query("SELECT * FROM COURSE WHERE CourseID=".$cur, $link)))
{
DisplayErrMsg(sprintf("internal error %d:%s\n", mysql_errno(), mysql_error()));
return 0;
}
$row = mysql_fetch_array($result);
$session_data["CurCourseID"] = $cur;
$session_data["Cost"] = $row["Cost"];
$session_data["Number"] = $row["Number"];
$session_data["Subj"] = $row["Subj"];
}
$form_value["Cost"] = "value=\"".($row["Cost"])."\"";
$form_value["Number"] = "value=\"".($row["Number"])."\"";
$form_value["Subj"] = "value=\"".($row["Subj"])."\"";
$smarty->assign("form_value",$form_value);
//took out states here
if (!($new_result = mysql_query("INSERT INTO ORDERS
(FirstName, LastName, StudentID, CourseID, Total, CreditCardNumber, CreditCardExpires, PurchaseType, PayMethod, Format, ShipTo, ShippingAddress,
ShippingCity,
ShippingStateID,
ShippingZIP,
Date) Values
('".addslashes($form_firstname)."',
'".addslashes($form_lastname)."',
'".$session_data["CurStudentID"]."',
'".$session_data["CurCourseID"]."',
'".$session_data["Cost"]."',
'$form_ccnumber',
'".$expiresyear."-".$expiresmonth."',
'$form_purchtype',
'$form_paymentmethod',
'$form_formattype',
'$form_shipto',
'".addslashes($form_shipaddr1)."',
'".addslashes($form_shipcity)."',
'$form_shipstateid',
'$form_shipzip',".(mktime()).")", $link)))
{
DisplayErrMsg(sprintf("91internal error %d:%s\n", mysql_errno(), mysql_error()));
exit();
}
header("Location:paymethod_finish.php"); // print confirm page
exit();
} else // get data to build form
{
//took out the rest of the states info here
$execjs = "<SCRIPT LANGUAGE=\"JavaScript\">\n";
$execjs .= "<!--\n";
$execjs .= "function checkChoice(whichselect) {\n";
$execjs .= "with (whichselect.form) {\n";
$execjs .= "if (whichselect.checked == false)\n";
$execjs .= "hiddentotal.value = eval(hiddentotal.value) - eval(whichselect.value);\n";
$execjs .= "else\n";
$execjs .= "hiddentotal.value = eval(hiddentotal.value) + eval(whichselect.value) + ;\n";
$execjs .= "return(formatCurrency(hiddentotal.value));\n";
$execjs .= " }\n";
/$execjs .= "}\n";
$execjs .= "function formatCurrency(num) {\n";
$execjs .= "num = num.toString().replace(/\$|\,/g,'');\n";
$execjs .= "if(isNaN(num)) num = "0";\n";
$execjs .= "cents = Math.floor((num100+0.5)%100);\n";
$execjs .= "num = Math.floor((num100+0.5)/100).toString();\n";
$execjs .= "if(cents < 10) cents = "0" + cents;\n";
$execjs .= "for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)\n";
$execjs .= "num = num.substring(0,num.length-(4i+3))+','+num.substring(num.length-(4i+3));\n";
$execjs .= "return ("$" + num + "." + cents);\n";
$execjs .= "};\n";/
$execjs .= "}\n";
$execjs .= "-->\n";
$execjs .= "</SCRIPT>\n";
$smarty->assign('execjs',$execjs);
$smarty->assign("id_course",$session_data["CurCourseID"]);
session_register("session_data");
$smarty->assign("page","pay_method");
$smarty->display("pay_method.tpl");
exit();
?>
And here is the htm page that has the rest of code:
with some taken out so less chars on post.
{include file="header.tpl"}
{$execjs}
<form method="POST" action="pay_method.php?check=yes" name="data">
<table border="0" width="100%" id="table4" cellspacing="0" cellpadding="0">
<TR>
<TD><table border="0" id="table4" cellspacing="0" cellpadding="0">
<!--
<tr>
<td width="4" rowspan="2" valign="top"> </td>
<td valign="top"><font class="h" id="clr_blue"><br>
Pay_method</font>
<font class="text"><br>
</font>
</td>
</tr>
-->
................................deleted stuff here.
<tr>
<td>Choose format: </td>
<td colspan="2"><select name=form_formattype hidden value="15.00" onChange="this.form.total.value=checkChoice(this);">
{html_options values=$formattype_names selected=$formattype_id output=$formattype_names}
</select>
</td>
</tr>
<tr>
<td>(<strong>For hard copy</strong>)<br>
Select shipping address:</td>
<td colspan="2"><select name="form_shipto">
{html_options values=$shipto_names selected=$shipto_id output=$shipto_names}
</select>
</td>
</tr>
<tr>
<td> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="3">(If other chosen, enter new shipping address)<strong>.</strong></td>
</tr>
<tr>
<td>Shipping Address: </td>
<td colspan="2"><input name="form_shipaddr1" type="text" class="str" size="40" maxlength="50" onChange="noway();" {$form_value.ShippingAddress}></td>
</tr>
<tr>
<td> City: </td>
<td colspan="2"><input name="form_shipcity" type="text" class="str" size="40" maxlength="25" {$form_value.ShippingCity}></td>
</tr>
<tr>
<td>State:</td>
<td><select name="form_shipstateid" size="1">
{html_options values=$state_ids selected=$state_sel output=$states}
</select>
</td>
</tr>
<tr>
<td> Zip Code:</td>
<td colspan="2"><input name="form_shipzip" type="text" class="str" size="40" maxlength="5" {$form_value.ShippingZip}></td>
</tr>
<tr>
<td> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td><strong>Purchased Course</strong></td>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="3"><hr noshade size="1"></td>
</tr>
<tr>
<td>Course Number:</td>
<td colspan="2">
<input name="form_number" type="text" class="str" size="20" readonly="true" {$form_value.Number}></td>
</tr>
<tr>
<td>Subject:</td>
<td colspan="2">
<input name="form_subj" type="text" class="str" size="50" readonly="true" {$form_value.Subj}></td>
</tr>
<tr>
<td> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td>Shipping:</td>
<td colspan="2"><input name="form_shippingcost" type="text" class="str" size="20" readonly="true" {$form_value.ShippingCost}></td>
</tr>
<tr>
<td><strong>(Washington State students only)</strong><br>
State Sales Tax:<br> </td>
<td colspan="2"><input name="form_watax" type="text" class="str" size="20" readonly {$form_value.WashSalesTax}></td>
</tr>
<tr>
<td>Total:</td>
<td colspan="2">
<input name="form_cost" type="text" class="str" size="20" readonly {$form_value.Cost}><input type=hidden name=hiddentotal value=0>
</td>
</tr>
<tr>
<td> </td>
<td colspan="2"><input type="submit" class="btn" id="clr_menu" value="Submit" name="B22" ></td>
</table>
</form>
{include file="footer.tpl"}