PHP Page Need to pass Javascript calculated value to redirect page

J

JCCDevel

Hi All,

I'm trying to do something I thought would be simple (of course!)

1) ON a php page, calculate fees based upon user entires. I'm
calculating it in a javascript function and that is working well(based
upun using alerts to view values). However, I need to take that
calculated amount and pass it to a new page on redirect. This is the
calc function which seems to be working ok:

<code>

<script language="JavaScript">
function calc(fees){
var Discount = 0.90;
var WitnessCity1Loc = document.form1.WitnessCity1.value;
var Witness1Fee = 0;
var WitnessCity2Loc = document.form1.WitnessCity2.value;
var Witness2Fee = 0;
var WitnessCity3Loc = document.form1.WitnessCity3.value;
var Witness3Fee = 0 ;
var WitnessCity4Loc = document.form1.WitnessCity4.value;
var Witness4Fee = 0 ;
var FeeCalcTotal ;

if (WitnessCity1Loc == "Lowell")
{
Witness1Fee = 50;
}
else
{
Witness1Fee = 55;
}

if (WitnessCity2Loc != ""){
if (WitnessCity2Loc == "Lowell")
{
Witness2Fee = 50;
}
else
{
Witness2Fee = 55;
}
}

if (WitnessCity3Loc != ""){
if (WitnessCity3Loc == "Lowell")
{
Witness3Fee = 50;
}
else
{
Witness3Fee = 55;
}
}

if (WitnessCity4Loc != ""){
if (WitnessCity4Loc == "Lowell")
{
Witness4Fee = 50;
}
else
{
Witness4Fee = 55;
}
}


FeeCalcTotal = (Witness1Fee + Witness2Fee + Witness3Fee +
Witness4Fee)* Discount;

document.form1.chargetotal.value = FeeCalcTotal

</code>

Two things are supposed to happen when the submit button is pressed.
First, this happens:

<code>
<form name="form1" method="post" action="/cgi/formmail">
</code>

and then this is supposed to happen:

<code>
<input type="hidden" name="redirect" value="http://www.pagename.com/v3/
payment_pg.php?FeeCalcTotal=" & chargetotal& " " >
</code>

The post and the redirect are working but I just cannot seem to get
the calculated value passed on to the next page. Am I doing this
correctly? I'm used to doing this sort of thing on web pages that live
on our own servers - this is for somebody's individual website.

Just in case the info above is fuzzy, here's what I need in words and
not code!

When the customer clicks submit, three things should happen:
1) javascript calculation is performed (working)
2) calculation is stored in a hidden variable (might be working)
3) there is a method post to /cgi/formmail
4) there is a redirect to payment_pg.php page. The javascript
calculation amount needs to be carried over to this page somehow

Thanks in advance for any help you can give!

JCC
 
D

Doug Gunnoe

When the customer clicks submit, three things should happen:
1) javascript calculation is performed (working)
2) calculation is stored in a hidden variable (might be working)
3) there is a method post to /cgi/formmail
4) there is a redirect to payment_pg.php page. The javascript
calculation amount needs to be carried over to this page somehow

Thanks in advance for any help you can give!

JCC

You pass the form to /cgi/formmail which sends an email or whatever
and then formail also uses the value of the hidden input field named
redirect, which is a string of a URL with params, to do a redirect to
your php page?
<input type="hidden" name="redirect" value="http://www.pagename.com/v3/
payment_pg.php?FeeCalcTotal=" & chargetotal& " " >

This string is the problem. ^^ This really does not do anything. What
is chargetotal?

You could construct the url form formmail, because you already have
the value you need in
'document.form1.chargetotal.value = FeeCalcTotal'

or if you still want to construct the URL in the redirect field from
the same page, you would need to do something like this:

document.form1.redirect.value = "http://www.pagename.com/v3/
payment_pg.php?FeeCalcTotal=" + FeeCalcTotal;

I hope that helps. Good luck.
 
S

SAM

JCCDevel a écrit :
1) ON a php page, calculate fees based upon user entires. I'm
calculating it in a javascript function and that is working well(based
upun using alerts to view values). However, I need to take that
calculated amount and pass it to a new page on redirect. This is the
calc function which seems to be working ok:

<script language="JavaScript">

No ! old fashion

function calc(fees){

why 'fees' while it is not used ?
var Discount = 0.90;
var WitnessCity1Loc = document.form1.WitnessCity1.value;
var Witness1Fee = 0;
var WitnessCity2Loc = document.form1.WitnessCity2.value;
var Witness2Fee = 0;
var WitnessCity3Loc = document.form1.WitnessCity3.value;
var Witness3Fee = 0 ;
var WitnessCity4Loc = document.form1.WitnessCity4.value;
var Witness4Fee = 0 ;
var FeeCalcTotal ;

if (WitnessCity1Loc == "Lowell")
{
Witness1Fee = 50;
}
else
{
Witness1Fee = 55;
}

if (WitnessCity2Loc != ""){
Witness2Fee = (WitnessCity2Loc == "Lowell")? 50 : 55;
}
if (WitnessCity3Loc != ""){
if (WitnessCity3Loc == "Lowell")
{
Witness3Fee = 50;
}
else
{
Witness3Fee = 55;
}
}

if (WitnessCity4Loc != ""){
if (WitnessCity4Loc == "Lowell")
{
Witness4Fee = 50;
}
else
{
Witness4Fee = 55;
}
}


FeeCalcTotal = (Witness1Fee + Witness2Fee + Witness3Fee +
Witness4Fee)* Discount;

document.form1.chargetotal.value = FeeCalcTotal

return true;
// end of function
}
<form name="form1" method="post" action="/cgi/formmail"

onsubmit="return calc('I don't know what');">
and then this is supposed to happen:

<code>
<input type="hidden" name="redirect" value="http://www.pagename.com/v3/
payment_pg.php?FeeCalcTotal=" & chargetotal& " " >

Why that for ?
We just need :

<input type=hidden name="chargetotal">

the cgi will know witch page to redirect and the total charges.
To him to construct the right url
payment_pg.php?FeeCalcTotal=1.000.000

if not --> end of function 'calc(fees)' :

document.form1.chargetotal.value = FeeCalcTotal;
var cgi = 'http://www.pagename.com/v3/payment_pg.php?FeeCalcTotal=';
cgi += FeeCalcTotal;
document.form1.redirect.value = cgi;
return true;
}
 
J

JCCDevel

Thank you both for your replies! I think I'm clear on how to resolve
the issue now

I truly appreciate the time you took to explain this

JCC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top