[ic] Simple if-then to compare checkout page variable to updated variable after page update? What am I doing wrong?

Ed LaFrance edl@newmediaems.com
Mon, 26 Feb 2001 10:19:14 -0800


At 11:37 AM 02/25/2001 -0500, you wrote:
>Apologies for the previous HTML...fixed the formatiing...
>
>Hello all,
>
>     After staring at the screen trying to figure out my undoubtedly dumb
>mistake, I'm cross-eyed and need another head or three to look at this and
>point out my thickiness. I am attempting to set a scratch variable to the
>value of the form variable "country" on the checkout page. Then after
>someone has updated the shipping info and the page hs been resubmitted I
>want to compare the scratch variable containing the pre-update country value
>to the just-submitted new country value, and then of course set the scratch
>variable to this most recent value for further comparisons. I thought I
>understood the sequence of processing an Interchange page but I must be
>missing something. It seems to me that the comparison between the old
>country value (in a scratch variable) and the newly updated form country
>value should proceed before the scratch variable is updated with the new
>country value, but my comparison ALWAYS returns true, that they are equal.
>This is a code snippet:
>
>
>FIRST VISIT TO PAGE?
>
>[if !scratch visitcount]
>    [perl]
>       $Values->{country} = CA0;
>       $Values->{state} = QC;
>       $Values->{mv_shipmode} = "can_a";
>       $Scratch->{visitcount} = 1;
>       $Scratch->{previouscountry} = $Values->{country};
>       return "FIRST VISIT.\n";
>    [/perl]
>[else]
>
>PROBLEM HERE:
>
>    [perl]
>       $prevcountry = $Scratch->{previouscountry};
>       $country = $Values->{country};
>     ------->  if("$prevcountry" eq "$country") {  <------- ALWAYS TRUE, WHEN
>DOES FORM VARIABLE "COUNTRY" GET NEW VALUE?
>          $info = "COUNTRY NOT CHANGED, previous country is " .
>$Scratch->{previouscountry} . " and current country is
>$Values->{country}.\n";
>          $info;
>       }
>
>       else {
>
>          if("$Values->{country}" eq "CA0") {
>             $Values->{state} = "QC";
>             $Values->{zip} = "";
>             $Values->{mv_shipmode} = "can_a";
>             $info = "COUNTRY SET TO CANADA, previous country is " .
>$Scratch->{previouscountry} . " and current country is
>$Values->{country}.\n";
>             $info;
>             $Scratch->{previouscountry} = $Values->{country};
>          }
>          elsif("$Values->{country}" eq "US0") {
>             $Values->{mv_shipmode} = "can_us_a";
>             $Values->{salestax} = "";
>             $Values->{state} = "NJ0";
>             $Values->{zip} = "";
>             $info = "COUNTRY SET TO US, previous country is " .
>$Scratch->{previouscountry} . " and current country is
>$Values->{country}.\n";
>             $info;
>             $Scratch->{previouscountry} = $Values->{country};
>          }
>          else {
>             $Values->{mv_shipmode} = "can_intl_a";
>             $Values->{salestax} = "";
>             $Values->{state} = "";
>             $Values->{zip} = "";
>             $info = "COUNTRY SET TO INT, previous country is " .
>$Scratch->{previouscountry} . " and current country is
>$Values->{country}.\n";
>             $info;
>             $Scratch->{previouscountry} = $Values->{country};
>          }
>
>       }
>    [/perl]
>[/else]
>[/if]
>
>
>I just can't see why something that seems so simple isn't working, which
>means it's time for wiser heads to prevail. Could someone take a moment to
>correct either my understanding of the whole page processing operations or
>(I hope) point out a really dumb error?

Tim -

I put your code on a checkout page and it worked fine.  You probably 
weren't seeing the messages you expected because $info was not the last 
statement of each conditional block, but I made that minor change in my 
copy and everything is hunky-dory.  Your trouble must lie elsewhere - 
perhaps in the submission of the form on the country change event.  Verify 
your mv_todo value and any mv_checks or mv_clicks to make sure the form is 
actually submitting the data, and - I know this sounds too obvious - check 
the spelling on your form input for country.

- Ed L.