PHP Page Need to pass Javascript calculated value to redirect page

Discussion in 'Javascript' started by JCCDevel, Feb 26, 2008.

  1. JCCDevel

    JCCDevel Guest

    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
     
    JCCDevel, Feb 26, 2008
    #1
    1. Advertising

  2. JCCDevel

    Doug Gunnoe Guest

    Re: PHP Page Need to pass Javascript calculated value to redirectpage

    On Feb 26, 3:27 pm, JCCDevel <> wrote:

    > 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.
     
    Doug Gunnoe, Feb 26, 2008
    #2
    1. Advertising

  3. JCCDevel

    SAM Guest

    Re: PHP Page Need to pass Javascript calculated value to redirectpage

    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

    <script type="text/javascript">

    > 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
    }
    </script>

    > <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;
    }


    > 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


    --
    sm
     
    SAM, Feb 26, 2008
    #3
  4. JCCDevel

    JCCDevel Guest

    Re: PHP Page Need to pass Javascript calculated value to redirectpage

    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
     
    JCCDevel, Feb 27, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    442
  2. Rajive Narain
    Replies:
    0
    Views:
    1,988
    Rajive Narain
    Sep 18, 2009
  3. Sal
    Replies:
    1
    Views:
    799
  4. J-P-W
    Replies:
    6
    Views:
    162
    J-P-W
    Sep 7, 2006
  5. Chris Allen

    Taking a reference to a calculated value

    Chris Allen, Sep 7, 2004, in forum: Perl Misc
    Replies:
    5
    Views:
    79
    Chris Allen
    Sep 8, 2004
Loading...

Share This Page